4) MySQL 刪除資料表

2023-01-28 21:21:18 字數 890 閱讀 1177

mysql中刪除資料表是非常容易操作的, 但是你再進行刪除表操作時要非常小心,因為執行刪除命令後所有資料都會消失。

以下為刪除mysql資料表的通用語法:

drop table 資料表

以下例項刪除了資料表runoob_tbl:

[email protected]# mysql -u root -p

enter password:*******

mysql> use runoob;

database changed

mysql> drop table runoob_tbl

query ok, 0 rows affected (0.8 sec)

mysql>

關於刪除的幾種情況

1.刪除表內資料,用 delete。格式為:

delete from 表名 where 刪除條件;

例項:刪除學生表內姓名為張三的記錄。

delete from student where t_name = "張三";

2.清除表內資料,儲存表結構,用 truncate。格式為:

truncate table 表名;

例項:清除學生表內的所有資料。

truncate table student;

3.刪除表用 drop,就是啥都沒了。格式為:

drop table 表名;

例項:刪除學生表。

drop table student;

4.刪除表中某一列的值(不刪除列欄位)

update 表名 set 列=值;

1、當你不再需要該表時, 用 drop;

2、當你仍要保留該表,但要刪除所有記錄時, 用 truncate;

3、當你要刪除部分記錄時, 用 delete。

MySQL 刪除資料表

mysql中刪除資料表是非常容易操作的,但是你在進行刪除表操作時要非常小心,因為執行刪除命令後所有資料都會消失。以下為刪除mysql資料表的通用語法 drop table table name 在mysql 命令提示視窗中刪除資料表sql語句為drop table 以下例項刪除了資料表runoob ...

MySQL 刪除資料表

mysql中刪除資料表是非常容易操作的,但是你在進行刪除表操作時要非常小心,因為執行刪除命令後所有資料都會消失。語法 drop table table name 在命令提示視窗中刪除資料表在mysql 命令提示視窗中刪除資料表sql語句為drop table 例項 root host mysql u...

MySQL(11) 刪除資料表

mysql中刪除資料表是非常容易操作的,但是你再進行刪除表操作時要非常小心,因為執行刪除命令後所有資料都會消失。以下為刪除mysql資料表的通用語法 drop table table name 在mysql 命令提示視窗中刪除資料表sql語句為drop table 以下例項刪除了資料表runoob ...