如何檢查 MySQL 資料庫中已存在的空表?
要檢查資料庫中是否存在空表,你需要從表中提取一些記錄。如果表不為空,則會返回表記錄。
讓我們首先建立一個表 -
mysql> create table DemoTable(Id int,Name varchar(100),Age int); Query OK, 0 rows affected (0.80 sec)
使用 insert 命令向表中插入一些記錄 -
mysql> insert into DemoTable values(1001,'John',23); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(1002,'Chris',21); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(1003,'David',22); Query OK, 1 row affected (0.19 sec)
使用 select 語句顯示錶中的所有記錄 -
mysql> select *from DemoTable;
這將產生以下輸出 -
+------+-------+------+ | Id | Name | Age | +------+-------+------+ | 1001 | John | 23 | | 1002 | Chris | 21 | | 1003 | David | 22 | +------+-------+------+ 3 rows in set (0.00 sec)
讓我們從表中刪除所有記錄 -
mysql> delete from DemoTable where Id IN(1001,1002,1003); Query OK, 3 rows affected (0.19 sec)
現在根據 where 條件嘗試從表中獲取記錄 -
mysql> select Id from DemoTable where Name="John"; Empty set (0.00 sec)
你可以看到以上內容,由於表現在為空,因此會返回一個空集。
廣告