- 使用 DELETE 语句从表中删除数据
DELETE FROM table_name [WHERE <condition>];
table_name指定要执行删除操作的表;“[WHERE ]”为可选参数,指定删除条件,如果没有WHERE子句,DELETE语句将删除表中的所有记录。
- 使用 WHERE 子句删除指定的记录。
DELETE FROM departments
WHERE department_name = 'Finance';
- 如果省略 WHERE 子句,则表中的全部数据将被删除
DELETE FROM copy_emp;
- 删除中的数据完整性错误
DELETE FROM departments
WHERE department_id = 60;
说明:You cannot delete a row that contains a primary key that is used as a foreign key in another table.