search

Home  >  Q&A  >  body text

List of constraints in the database

<p>How to get a list of all constraints from a MySQL database? </p>
P粉752826008P粉752826008505 days ago501

reply all(1)I'll reply

  • P粉327903045

    P粉3279030452023-08-23 13:34:50

    Use information_schema.table_constraints table to get the name of the constraints defined on each table:

    select *
    from information_schema.table_constraints
    where constraint_schema = 'YOUR_DB'

    Use information_schema.key_column_usage table to obtain the fields in these constraints:

    select *
    from information_schema.key_column_usage
    where constraint_schema = 'YOUR_DB'

    If you want to discuss foreign key constraints, use information_schema.referential_constraints:

    select *
    from information_schema.referential_constraints
    where constraint_schema = 'YOUR_DB'

    reply
    0
  • Cancelreply