How to get list of MySQL database constraints

1143015 pts.
Tags:
Database
MySQL
Would I be able to get my list of constraints from my MySQL database? What SQL query should I use? Thank you so much.
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Thanks for coming to ITKE.

This should help you out.

Use the information_schema.table_constraints table to get the names of the constraints defined on each table:
select *
from information_schema.table_constraints
where constraint_schema = 'YOUR_DB'

Use the information_schema.key_column_usage table to get the fields in each one of those constraints:
select *
from information_schema.key_column_usage
where constraint_schema = 'YOUR_DB'

If instead you are talking about foreign key constraints, use information_schema.referential_constraints:
select *
from information_schema.referential_constraints
where constraint_schema = 'YOUR_DB'

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: