如何检查 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)
你可以看到以上内容,由于表现在为空,因此会返回一个空集。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP