Home > Database > Mysql Tutorial > How to update and delete in MySQL

How to update and delete in MySQL

PHPz
Release: 2023-06-02 12:49:06
forward
1396 people have browsed it

1. Update

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

Change the name corresponding to ID 12 to Laoha:

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

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 条件;
Copy after login

Delete the data corresponding to id equal to 9:

DELETE FROM users WHERE id = 9;
Copy after login

How to update and delete in MySQL

Delete all data:

DELETE FROM 表名;
Copy after login

TRUNCATE delete:

TRUNCATE TABLE 表名;
Copy after login

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, ...;
Copy after login

Delete database:

DROP DATABASE 数据库名字;
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template