Home > Database > Mysql Tutorial > Constraints for show table command in MySQL?

Constraints for show table command in MySQL?

WBOY
Release: 2023-09-15 14:37:06
forward
1400 people have browsed it

在 MySQL 中显示表命令的约束?

You can display constraints on a table with the help of the SHOW command. The syntax is as follows -

show create table yourTableName;
Copy after login

The above command will display all constraints of table ENGINE. Using it, you can even see all column names and corresponding data types.

To understand the above MySQL statement, let us first create a table -

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)
Copy after login

Now you can apply the above syntax to display the constraints on the table. The query is as follows -

mysql> show create table ShowConstraintsDemo;
Copy after login

The following is the output showing all constraints -

+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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)
Copy after login

The above is the detailed content of Constraints for show table command in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template