Show constraints on tables command

后端 未结 8 1277
慢半拍i
慢半拍i 2020-11-29 14:44

I have tables that I\'ve tried setting PK FK relationships on but I want to verify this. How can I show the PK/FK restraints? I saw this manual page, but it does not show ex

8条回答
  •  死守一世寂寞
    2020-11-29 15:27

    You can use this:

    select
        table_name,column_name,referenced_table_name,referenced_column_name
    from
        information_schema.key_column_usage
    where
        referenced_table_name is not null
        and table_schema = 'my_database' 
        and table_name = 'my_table'
    

    Or for better formatted output use this:

    select
        concat(table_name, '.', column_name) as 'foreign key',  
        concat(referenced_table_name, '.', referenced_column_name) as 'references'
    from
        information_schema.key_column_usage
    where
        referenced_table_name is not null
        and table_schema = 'my_database' 
        and table_name = 'my_table'
    

提交回复
热议问题