数据表的删除

查看数据表命令 | 必须先选择数据库

show tables;

使用 drop 命令删除MySQL数据表,语法如下:

DROP TABLE table_name ;            -- 直接删除表,不检查是否存在
DROP TABLE [IF EXISTS] table_name;

参数说明:

  • table_name 是要删除的表的名称
  • IF EXISTS 是一个可选的子句,表示如果表存在才执行删除操作,避免因为表不存在而引发错误

示例:

DROP TABLE Username;
DROP TABLE IF EXISTS Username;

删除成功如下:

mysql> DROP TABLE Username;
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
Empty set (0.00 sec)

results matching ""

    No results matching ""