您可以藉助 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 中顯示表格指令的約束?的詳細內容。更多資訊請關注PHP中文網其他相關文章!