Home  >  Article  >  Database  >  How to update and delete in MySQL

How to update and delete in MySQL

PHPz
PHPzforward
2023-06-02 12:49:061337browse

1. Update

UPDATE 表名 SET 字段1 = 值1, 字段2 = 值2,... WHERE 条件;

Change the name corresponding to ID 12 to Laoha:

update users SET name = '老哈' where id = 12;

How to update and delete in MySQL

##2. Delete

You can delete one record or multiple records in the table through DELETE

DELETE FROM 表名 WHERE 条件;

Delete the data corresponding to id equal to 9:

DELETE FROM users WHERE id = 9;

How to update and delete in MySQL

Delete all data:

DELETE FROM 表名;

TRUNCATE delete:

TRUNCATE TABLE 表名;

The difference between DELETE and TRUNCATE:

  • DELETE supports conditions, TRUNCATE does not support conditions

  • DELETE supports transaction rollback, TRUNCATE does not support rollback

  • DELETE cleanup speed is slower than TRUNCATE

  • TRUNCATE auto-increment value will be initialized

Delete table:

DROP TABLE 表名1, 表名2, ...;

Delete database:

DROP DATABASE 数据库名字;

The above is the detailed content of How to update and delete in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete