您可以借助 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.92cms.cn其它相關文章!