How can I see the constraints which are applied to a table stored in the database I am currently using?


MySQL SHOW CREATE TABLE statement will provide us the constraints applied to a particular table along with some other details about that table. Its syntax would be as follows −

Syntax

SHOW CREATE TABLE table_name;

Here table_name is the name of the table on which we want to see the constraints.

Example

In this example we are getting the detail of the table named ‘employees’ −

mysql> Show Create table employees\G
*************************** 1. row ***************************
       Table: employees
Create Table: CREATE TABLE `employees` (
   `Id` int(11) NOT NULL AUTO_INCREMENT,
   `Name` varchar(35) DEFAULT NULL,
   PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

The above result set shows that there is a PRIMARY KEY constraint on column ’id’ in table ‘employees’.

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 19-Jun-2020

47 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements