1. Data manipulation
Data tables are used to store specific data, and once you have an understanding of the data table, you should know how the data table holds the data.
1.1 Add record (insert data)
Grammar:
Insert into Table name (field list) VALUES (list of values);
It is important to note that the field list and the list of values are separated by commas in English. Field names are best used in reverse quotation marks.
Multiple data can be inserted in MySQL, and multiple data means that the list of values is multiple. Like what:
Insert into Table name (field list) VALUES (Value List 1), (Value List 2);
The order of the list of values needs to be the same as the order of the field list, such as the first of the field list is the ID, then the first of the value list should also be the value corresponding to the ID.
1.2 Querying data
Grammar:
Select field List from table name;
This statement can query the value of a specified field from a table, querying for all data, that is, how many bars are displayed in the data table.
The list of fields is separated by commas, * denotes all fields. Such as:
select * from user;
Represents: Queries all data in the user table.
In SQL, an SQL statement can be made up of a number of SQL clauses, which are the ones that make up the SQL statement, usually the keywords of some columns, such as the SELECT clause that starts with SELECT. FROM clause. And the WHERE clause with the most with the select, such as:
SELECT * from user where id>5;
where represents the condition of the query. This sentence can be translated as: Query the user table, all id>5 data.
More complex queries we will learn in the following chapters, where there is a certain concept of simple queries first.
1.3 Deleting Records
Grammar:
Delete from table name [WHERE clause];
When you delete data, the WHERE clause becomes more important, and if you do not add a WHERE clause as a delete condition, the DELETE statement kills all the data in the data table.
Delete from user where id=5;
This sentence means deleting the id=5 data in the user table,
It is important to note that in MySQL, = represents a comparison operator, not an assignment.
1.4 Update data (modify data)
Grammar:
Update table name Set field = value, field = value [WHERE clause];
Similarly, if there is no WHERE clause as a constraint, update will get rid of all the data in the table
Update user set Username= "Zhangsan" where id=1;
This is interpreted as: Modify the username in the id=1 data in the user table to Zhangsan;
1.5 Curd
In the actual work, you will often hear curd operation, it is actually representative of the data can be deleted and modified. This is roughly what we do with frost. Just add some more complicated logic.
C:create Create
U:update Update
R:retrieve Read
D:delete Delete
[Daily update-mysql] 4. Recording operations (data manipulation)