SELECT    fk.name AS foreign_key_name,
oSub.name AS table_name,
SubCol.name AS table_column,
oMain.name AS references_table_name,
MainCol.name AS references_table_column,
fk.delete_referential_action_desc
FROM sys.foreign_keys fk
JOIN sys.all_objects oSub ON(fk.parent_object_id = oSub.object_id)
JOIN sys.all_objects oMain ON(fk.referenced_object_id = oMain.object_id)
JOIN sys.foreign_key_columns fkCols ON(fk.object_id = fkCols.constraint_object_id)
JOIN sys.columns SubCol ON(oSub.object_id = SubCol.object_id AND fkCols.parent_column_id = SubCol.column_id)
JOIN sys.columns MainCol ON(oMain.object_id = MainCol.object_id AND fkCols.referenced_column_id = MainCol.column_id)
WHERE fk.delete_referential_action_desc = 'CASCADE'
ORDER BY oSub.name ;

SQL 查询表外键_T-Sql 2016——级联删除外键查询-LMLPHP

05-11 16:27