MySQL 删除数据表
用 DROP TABLE 删表,结构与数据一同消失。
Key PointsDROP TABLE 删除表结构和全部数据,和 DROP DATABASE 一样不可逆。
基本语法
SQL
DROP TABLE users;
DROP TABLE IF EXISTS users; -- 存在才删
DROP TABLE a, b; -- 一次删多张Output
Query OK, 0 rows affected (0.02 sec)Dropping a table referenced by a foreign key fails with
Cannot delete or update a parent row. Drop the child first, or remove the FK constraint.基本语法
SQL
DROP TABLE users;
DROP TABLE IF EXISTS users; -- 存在才删
DROP TABLE a, b; -- 一次删多张Output
Query OK, 0 rows affected (0.02 sec)有外键引用时,直接 DROP 会报
Cannot delete or update a parent row。先删子表,或先 DROP FOREIGN KEY 再删。