Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 484 Bytes

mysql.md

File metadata and controls

24 lines (18 loc) · 484 Bytes

MySQL

Show table constraints

Show indexes and constraints:

SHOW CREATE TABLE $table_name;

Show contraints only:

USE INFORMATION_SCHEMA;
SELECT TABLE_NAME,
       COLUMN_NAME,
       CONSTRAINT_NAME,
       REFERENCED_TABLE_NAME,
       REFERENCED_COLUMN_NAME
FROM KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = "$database_name"
      AND TABLE_NAME = "$table_name";
      AND REFERENCED_COLUMN_NAME IS NOT NULL;