mysql刪除表有三種方法:

創(chuàng)新互聯(lián)主要從事網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)云夢,十余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108
1、不再需要該表時(shí), 用?drop;
例如:drop table tb;
drop 是直接將表格刪除,無法找回。
2、仍要保留該表,但要?jiǎng)h除所有記錄時(shí), 用?truncate;
例如:TRUNCATE TABLE user;??????? 刪除表中所有數(shù)據(jù),但不能與where一起使用;
3、要?jiǎng)h除部分記錄或者有可能會(huì)后悔的話, 用?delete。
例如:delete from user;????????????刪除user表所有數(shù)據(jù)
delete from user where username ='Tom';? 刪除指定行。
01
如圖,比如我有一張數(shù)據(jù)表studentinfo,我想要?jiǎng)h除studentid為1009的這條數(shù)據(jù)。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
02
我們可以直接點(diǎn)擊設(shè)計(jì)界面下方的減號(hào)來刪除數(shù)據(jù)。如圖,選中數(shù)據(jù),然后點(diǎn)擊減號(hào)按鈕。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
03
點(diǎn)擊減號(hào)之后,就會(huì)彈出一個(gè)提示框,問你是否要?jiǎng)h除這條數(shù)據(jù)。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
04
之后,選中的數(shù)據(jù)記錄就從數(shù)據(jù)表中刪除掉了。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
05
也可以使用SQL語句來刪除數(shù)據(jù)記錄,點(diǎn)擊查詢菜單下的“新建查詢”。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
06
如圖,在其中輸入delete from studentinfo where studentid=1001;
這樣就可以刪除studentid為1001 的數(shù)據(jù)記錄了。
Delete from 后面接的是表名,where后面接的是條件,
因?yàn)槲沂且獎(jiǎng)h除studentinfo表中studentid等于1001的記錄,所以就這樣寫。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
07
之后,點(diǎn)擊運(yùn)行按鈕來執(zhí)行刪除操作。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
08
如圖,回到之前的界面,需要點(diǎn)擊一下下邊的刷新按鈕。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
09
這樣,我們就可以看到1001的那條記錄已經(jīng)被刪除掉了。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
10
而如果想要?jiǎng)h除全部的數(shù)據(jù)記錄,可以直接輸入查詢語句:delete from studentinfo;
運(yùn)行之后就可以刪除全部的數(shù)據(jù)記錄了。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
11
如圖,所有的數(shù)據(jù)記錄都被刪除掉了。
請點(diǎn)擊輸入圖片描述
請點(diǎn)擊輸入圖片描述
刪除表數(shù)據(jù)有兩種方法:delete和truncate。具體語句如下:
一、RUNCATE TABLE name? :
刪除表中的所有行,而不記錄單個(gè)行刪除操作。?在這個(gè)指令之下,表格中的資料會(huì)完全消失,可是表格本身會(huì)繼續(xù)存在。
TRUNCATE TABLE 的語法:TRUNCATE TABLE name ,參數(shù) name 是要截?cái)嗟谋淼拿Q或要?jiǎng)h除其全部行的表的名稱。
二、Delete from tablename where 1=1
1、delete語法:
DELETE FROM 表名稱 WHERE 列名稱 = 值。
2、刪除所有行:
可以在不刪除表的情況下刪除所有的行。這意味著表的結(jié)構(gòu)、屬性和索引都是完整的:DELETE FROM table_name。
DROP TABLE table_name (刪除表);delete from 表名 where 刪除條件(刪除表內(nèi)數(shù)據(jù),用?delete);truncate table 表名(清除表內(nèi)數(shù)據(jù),保存表結(jié)構(gòu),用?truncate)。
擴(kuò)展資料:
1、MySQL中刪除數(shù)據(jù)表是非常容易操作的, 但是你再進(jìn)行刪除表操作時(shí)要非常小心,因?yàn)閳?zhí)行刪除命令后所有數(shù)據(jù)都會(huì)消失。
2、命令提示窗口中刪除數(shù)據(jù)表:SQL語句為?DROP TABLE 。
3、使用PHP腳本刪除數(shù)據(jù)表:PHP使用 mysqli_query 函數(shù)來刪除 MySQL 數(shù)據(jù)表。該函數(shù)有兩個(gè)參數(shù),在執(zhí)行成功時(shí)返回 TRUE,否則返回 FALSE。語法mysqli_query(connection,query,resultmode)。
4、當(dāng)你不再需要該表時(shí), 用?drop;當(dāng)你仍要保留該表,但要?jiǎng)h除所有記錄時(shí), 用?truncate;當(dāng)你要?jiǎng)h除部分記錄時(shí), 用?delete。
5、drop table table_name?: 刪除表全部數(shù)據(jù)和表結(jié)構(gòu),立刻釋放磁盤空間,不管是 Innodb 和 MyISAM。實(shí)例,刪除學(xué)生表:drop table student。
6、truncate table table_name?: 刪除表全部數(shù)據(jù),保留表結(jié)構(gòu),立刻釋放磁盤空間 ,不管是 Innodb 和 MyISAM。實(shí)例,刪除學(xué)生表:truncate table student。
7、delete from table_name?: 刪除表全部數(shù)據(jù),表結(jié)構(gòu)不變,對于 MyISAM 會(huì)立刻釋放磁盤空間,InnoDB 不會(huì)釋放磁盤空間。實(shí)例,刪除學(xué)生表:delete from student。
8、delete from table_name where xxx?: 帶條件的刪除,表結(jié)構(gòu)不變,不管是 innodb 還是 MyISAM 都不會(huì)釋放磁盤空間。實(shí)例,刪除學(xué)生表中姓名為 "張三" 的數(shù)據(jù):delete from student where T_name = "張三"。
9、delete 操作以后,使用?optimize table table_name?會(huì)立刻釋放磁盤空間,不管是 innodb 還是 myisam。實(shí)例,刪除學(xué)生表中姓名為 "張三" 的數(shù)據(jù):delete from student where T_name = "張三"。
10、delete from?表以后雖然未釋放磁盤空間,但是下次插入數(shù)據(jù)的時(shí)候,仍然可以使用這部分空間。
文章名稱:mysql怎么清除數(shù)據(jù)表 mysql怎么清除表里數(shù)據(jù)
分享URL:http://chinadenli.net/article30/hpjpso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、自適應(yīng)網(wǎng)站、服務(wù)器托管、做網(wǎng)站、網(wǎng)站導(dǎo)航、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)