mysql中對(duì)于刪除語(yǔ)句大全總結(jié)(上)
發(fā)表時(shí)間:2023-07-21 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]1.drop語(yǔ)句?梢杂脕(lái)刪除數(shù)據(jù)庫(kù)和表。A用drop語(yǔ)句來(lái)刪除數(shù)據(jù)庫(kù):mysql> drop database hello;Query OK, 0 rows affected (0.19 s...
1.drop語(yǔ)句?梢杂脕(lái)刪除數(shù)據(jù)庫(kù)和表。
A用drop語(yǔ)句來(lái)刪除數(shù)據(jù)庫(kù):
mysql> drop database hello;Query OK, 0 rows affected (0.19 sec)
mysql> show databases;
+--------------------+
Database
+--------------------+
information_schema
mysql
performance_schema
sys
test
trains
+--------------------+
6 rows in set (0.00 sec)
B用drop語(yǔ)句來(lái)刪除表:
mysql> drop table q1;Query OK, 0 rows affected (0.39 sec)
mysql> show tables;
+------------------+
Tables_in_trains
+------------------+
4inall
ava
book
c1score
c2score
course
joke
sc
sc1
student
student1
teacher
+------------------+
12 rows in set (0.00 sec)
2.delete語(yǔ)句。用來(lái)刪除表中的字段:
A通過(guò)where子句來(lái)指定刪除表中的某個(gè)記錄:
mysql> delete from joke where gid=1;
mysql> select * from joke;
+------+-----------+-------+------+
gid name sex age
+------+-----------+-------+------+
3 xiaowan2 male 22
3 xiaowan2 male 22
3 xiaowan2 male 22
3 xiaowan22 1male 22
0 joker NULL NULL
0 joker NULL NULL
+------+-----------+-------+------+
6 rows in set (0.00 sec)
注意:如果delete語(yǔ)句中沒(méi)有加入where就會(huì)把表中的所有記錄全部刪除:
mysql> select * from student1;
+------+--------+------+------+
s sname sage ssex
+------+--------+------+------+
1 劉一 18 男
2 錢(qián)二 19 女
3 張三 17 男
4 李四 18 女
5 王五 17 男
6 趙六 19 女
+------+--------+------+------+
6 rows in set (0.00 sec)
mysql> delete from student1;Query OK, 6 rows affected (0.19 sec)
mysql> select * from student1;Empty set (0.00 sec)
B通過(guò)select子句來(lái)刪除表中的某個(gè)記錄:
mysql> delete from student1 where s in (select s from student where sage=18 and ssex="男");Query OK, 1 row affected (0.13 sec)
mysql> select * from student1;
+------+--------+------+------+
s sname sage ssex
+------+--------+------+------+
2 錢(qián)二 19 女
3 張三 17 男
4 李四 18 女
5 王五 17 男
6 趙六 19 女
+------+--------+------+------+
5 rows in set (0.00 sec)
3.用truncate來(lái)刪除表中的所以字段:
mysql> select * from student1;
+------+--------+------+------+
s sname sage ssex
+------+--------+------+------+
1 劉一 18 男
2 錢(qián)二 19 女
3 張三 17 男
4 李四 18 女
5 王五 17 男
6 趙六 19 女
+------+--------+------+------+
6 rows in set (0.00 sec)
mysql> truncate table student1;Query OK, 0 rows affected (0.28 sec)
mysql> select * from student1;Empty set (0.00 sec)
以上就是mysql中關(guān)于刪除語(yǔ)句大全總結(jié)(上)的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!
學(xué)習(xí)教程快速掌握從入門(mén)到精通的SQL知識(shí)。