
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Show constraints on table command in MySQL?
You can show constraints on tables with the help of SHOW command. The syntax is as follows −
show create table yourTableName;
The above command will show all constraints with table ENGINE. Using this, you can even see all the 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)
Now you can apply the above syntax in order to show constraints on tables. The query is as follows −
mysql> show create table ShowConstraintsDemo;
The following is the output that displays all the 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)
- Related Articles
- How do I show unique constraints of a table in MySQL?
- How to display all constraints on a table in MySQL?
- Update MySQL table on INSERT command with triggers?
- How to generate a “create table” command based on an existing table in MySQL?
- Combine SELECT & SHOW command results in MySQL?
- Show MySQL host via SQL Command?
- MySQL command to copy table?
- Rename a table in MySQL using RENAME TABLE command
- What does 'show processlist' command do in MySQL?
- How can we use MySQL ALTER TABLE command for adding comments on columns?
- Constraints on Generalization
- What are MySQL constraints?
- MySQL show tables sort by table name?
- SHOW TABLE statement with multiple LIKE values in MySQL?
- What information does SHOW TABLE DOES display in MySQL

Advertisements