sql >> Database teknologi >  >> RDS >> Mysql

Find ud af, om en tabel har en DELETE på CASCADE

Ja. Bare forespørg på INFORMATION_SCHEMA

SELECT * FROM information_schema.REFERENTIAL_CONSTRAINTS
 

Eller mere 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 mere om REFERENTIAL_CONSTRAINTS tabel i manualen



  1. Forskellen mellem MySQL ER IKKE NULL og !=''

  2. Hvordan returnerer man forskellige værdier og deres antal?

  3. Opret en SQL Server-database med Azure Data Studio

  4. Postgres kunne ikke oprette forbindelse til serveren