Abhinav
Abhinav

Reputation: 8168

View the constraints enforced on a table- SQL

Since I am not much of a DB guy, I have a query.I use Mysql. I am given a table which has around 12 columns and that table has a PRIMARY key,UNIQUE & a FOREIGN key defined.

Is there a way to find on which columns the constraints are defined?

I came across one query:

SHOW INDEX FROM tablt_name;

But It does not give a clear idea, only the primary key column is displayed by the above query.

If there is any other way to get the info, pls help

Upvotes: 1

Views: 48

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172618

You can try like thisL

USE information_schema; 

SELECT table_name, 
       column_name, 
       constraint_name, 
       referenced_table_name, 
       referenced_column_name 
FROM   key_column_usage 
WHERE  table_schema = "" 
       AND table_name = "" 
       AND referenced_column_name IS NOT NULL; 

or

DESCRIBE table_name

Upvotes: 1

Related Questions