您可以借助 show 命令显示表上的约束。语法如下 -
show create table yourtablename;
上述命令将显示表 engine 的所有约束。使用它,你甚至可以看到所有的列名和相应的数据类型。
为了理解上面的mysql语句,让我们首先创建一个表 -
mysql> create table showconstraintsdemo -> ( -> bookid int not null,-> bookname varchar(200) not null,-> bookauthor varchar(200) unique not null,-> primary key(bookid,bookname)-> );query ok, 0 rows affected (1.04 sec)
现在您可以应用上述语法来显示表上的约束。查询如下 -
mysql> show create table showconstraintsdemo;
以下是显示所有约束的输出 -
+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| table | create table |+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| showconstraintsdemo | create table `showconstraintsdemo` ( `bookid` int(11) not null, `bookname` varchar(200) collate utf8mb4_unicode_ci not null, `bookauthor` varchar(200) collate utf8mb4_unicode_ci not null, primary key (`bookid`,`bookname`), unique key `bookauthor` (`bookauthor`) ) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci |+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.05 sec)
以上就是在 mysql 中显示表命令的约束?的详细内容。