Hướng dẫn mysql delete all data
Từ khóa DELETE được dùng để xóa dữ liệu (hàng) trong bảng.Cú pháp xóa dữ liệu trong bảng
Một số ví dụChúng ta có một bảng sinh_vien như sau: (Bạn có thể bấm vào đây để download câu lệnh tạo bảng như bên dưới)
Xóa những sinh viên có giới tính là nam
Sau khi thực thi, bảng sinh_vien sẽ trở thành:
Xóa những sinh viên có giới tính nam và tuổi là 19
Sau khi thực thi, bảng sinh_vien sẽ trở thành:
Lưu ý:Đối với câu lệnh DELETE, nếu chúng ta bỏ mệnh đề WHERE thì MySQL sẽ xóa hết tất cả dữ liệu của bảng. 13.2.2 DELETE Statement A Single-Table Syntax
The Main Clauses The conditions in the optional If the Multiple-Table Syntax
Privileges You need the Performance When you do not need to know the number of deleted rows, the The speed of delete operations may also be affected by factors discussed in Section 8.2.5.3, “Optimizing DELETE Statements”. To ensure that a given SubqueriesYou cannot delete from a table and select from the same table in a subquery. Partitioned Table Support The For more information and examples, see Section 24.5, “Partition Selection”. Auto-Increment Columns If you delete the row containing the maximum value for an For Modifiers The
Order of Deletion If the
InnoDB Tables If you are deleting many rows from a large table, you may exceed the lock table size for an
No other sessions
can access the tables involved while MyISAM Tables In The
In this scenario, the index blocks associated with the deleted index values become underfilled but are not merged with other index blocks due to the use of If you are going to delete many rows from a table, it might be faster to use Multi-Table Deletes You can specify multiple tables in a For the first multiple-table syntax, only matching rows from the tables listed before the
Or:
These statements use all three tables when searching for rows to delete, but delete matching rows only from tables The preceding examples use
The syntax permits If you use a multiple-table Note If you declare an alias for a table, you must use the alias when referring to the table:
Table aliases in a multiple-table Correct:
Incorrect:
Table aliases are also supported for single-table |