SQL key basic statement learning summary

MySQL statement

Because when looking for software testing positions, many companies have different levels of requirements for MySOL (relational database) and SQL. Therefore, I am learning for the first time. In the previous article, I used the Navicat database management visualization tool to run I made a summary, but later I found that the visual tool presentation and summary are a bit messy, but I still summarize these knowledge points in detail so that I can return to view and review.

Query statement = SQL select statement

SELECT statement is used to select data from the database

1. The simplest: Find the table named "doctor" in the database, the syntax is as follows:
SELECT * FROM doctor;

2, hard some of them: pick qualified content from the table based on certain conditions
such as a table called "doctor" in doctorname = John Doe to find all the information, the following syntax
SELECT * FROM doctor WHERE doctorname = 'John Doe' ;

The above where, also belongs to the statement in SQL: SQL Where clause
WHERE clause is used to extract those records that meet the specified criteria, a simple understanding is that the content after where is the given condition. Therefore, it can be concluded that the operation syntax format of SELECT is:

The content required by the SELECT From source table Where conditions given

In fact, when you understand the law and summarize the format, you can basically use the law to calculate all the select statements.

 ① SQL AND & OR 运算符
 需求:从 "doctor" 表中选取级别为 "主任" 且age年龄大于 "40" 的所有医生:
 SELECT * FROM doctor WHERE level='主任' AND age > 40;

 ② SQL ORDER BY 关键字
 SELECT * FROM doctor ORDER BY age;
 一般是默认升序(ASC)
 需求:从doctor表格中,筛选出年龄最大的五位医生的信息
 SELECT * FROM doctor ORDER BY `age` DESC LIMIT 0, 5
 降序(DESC)

3. Advanced:

  1. SQL SELECT DISTINCT statement
    requirements: selecting a different value from the unique "age" column "doctor" in the table, i.e. to remove the "age" column duplicate values:
    the SELECT the DISTINCT Age the FROM Doctor;

  2. SQL SELECT TOP clause:
    Requirements: select the first two records from the "doctor" table
    SELECT * FROM doctor LIMIT 2;

Delete statement=SQL DELETE statement

The DELETE statement is used to delete records (rows) in a table.

DELETE FROM doctor WHERE doctorname=’张红军’ AND age=’40’;

Note: Be extra careful when deleting records! Because you can't do it again. However, as far as I know, the general company restricts the permission to delete data for testers, so this can be basically mastered.

Therefore, to summarize the delete statement format:

DELETE FROM Form name Where information to be deleted (information conditions given)

Add statement=SQL INSERT INTO statement

INSERT INTO statement is used to insert new records into the table

INSERT INTO doctor (doctorname,password, sex, phone,age)
VALUES (‘林七’,’xiaolin’,’男’,’18977775434’,’44’);

To insert data, we need to indicate that we insert the corresponding data in the specified column.
For example, the above operation demonstrates inserting a new row, inserting data in the "doctorname", "password", "sex" and "age" columns (the id field will be automatically updated), and the other columns are not specified, and the default is empty

Modify/update statement=SQL UPDATE statement

The UPDATE statement is used to update records that already exist in the table.
UPDATE doctor SET age='52', level='Director' WHERE doctorname='Zhang San';

Warning: When performing operations, UPDATE without a WHERE clause should be cautious, and then be cautious, and carry the where condition after the update statement, otherwise all data in the table will be changed to the required content.

The above are the SQL statements for adding, deleting, modifying, and checking, as well as filtering statements in ascending and descending order. The above is only used as the basic point of learning the basic introductory SQL database language learning, more in-depth, and continue to explore. All the above statements have passed the self-test operation successfully.

Guess you like

Origin blog.csdn.net/Yorkie_Lin/article/details/79735613