Basic operation of data in MySQL table-update, delete data

update data

In MySQL, you can use the UPDATE statement to update the data in the table, the syntax format is as follows:

UPDATE 表名
SET 字段名1=1[,字段名2=2,...]
[WHERE表达式]

In the above grammar, "field name" is used to specify the name of the field that needs to be updated, and "value" is used to indicate the new data of the field update. If you want to update the value of multiple fields, you can separate multiple fields and values ​​with commas, "WHERE Conditional expression" is optional and is used to specify the conditions that need to be met to update the data.
1. Update all data
When the UPDATE statement does not use the WHERE conditional statement, all the specified fields of all data in the table will be updated.
Update age in the T2 table to 30, the execution result is as follows:

Insert picture description here
2. Update all data In
actual development, most of the requirements are to update part of the data in the table. The WHERE clause can be used to specify the conditions for updating the data.
Modify the age of A to 20. The execution results are as follows:
Insert picture description here

delete data

Deleting data is also a common operation of the database.

Use DELETE to delete data

In MySQL, you can use the DELETE statement to delete data in the table. The syntax format is as follows:

DELETE FROM 表名 [WHERE 条件表达式];

the above

1. Delete all data
When the WHERE conditional statement is not used in the DELETE statement, all data in the table will be deleted.

2. Delete some data
Use the WHERE clause to specify the conditions for deleting data.
Delete the A data in the T2 table, the execution result is as follows:
Insert picture description here

Use TRUNCATE to delete data

In MySQL, there is another way to delete all data in the table. This way requires the TRUNCATE statement. The statement format is as follows.

TRUNCATE [TABLE] 表名;

Use the TRUNCATE statement to delete all data in the T2 table. The execution results are as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/javanofa/article/details/107561818