sql >> Databasteknik >  >> RDS >> Mysql

Ta reda på om en tabell har en DELETE på CASCADE

Ja. Fråga bara INFORMATION_SCHEMA

SELECT * FROM information_schema.REFERENTIAL_CONSTRAINTS

Eller mer specifikt

-- This query will list all constraints, their delete rule, 
-- the constraint table/column list, and the referenced table
SELECT 
  r.CONSTRAINT_NAME,
  r.DELETE_RULE, 
  r.TABLE_NAME,
  GROUP_CONCAT(k.COLUMN_NAME SEPARATOR ', ') AS `constraint columns`,
  r.REFERENCED_TABLE_NAME
FROM information_schema.REFERENTIAL_CONSTRAINTS r
  JOIN information_schema.KEY_COLUMN_USAGE k
  USING (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME)
-- using MySQL's GROUP BY clause. In other DB's more columns would need to be
-- specified!
GROUP BY r.CONSTRAINT_CATALOG,
         r.CONSTRAINT_SCHEMA,
         r.CONSTRAINT_NAME

Läs mer om REFERENTIAL_CONSTRAINTS tabell i manualen



  1. Grunderna för PostgreSQL Schema Management

  2. Ange standardvärde för en heltalskolumn SQLite

  3. pt-query-digest Alternatives - MySQL Query Management &Monitoring med ClusterControl

  4. Den repeterbara läsisoleringsnivån