您可以借助 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 中显示表命令的约束?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!