我使用这个脚本查询一些系统目录视图
SELECT
fk.name 'FK Name',
tpar.name 'Parent Table',
colpar.name 'Parent Column',
tref.name 'Referenced Table',
colref.name 'Referenced Column',
fk.delete_referential_action_desc 'Delete Action',
fk.update_referential_action_desc 'Update Action'
FROM
sys.foreign_keys fk
INNER JOIN
sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id
INNER JOIN
sys.tables tpar ON fk.parent_object_id = tpar.object_id
INNER JOIN
sys.columns colpar ON fkc.parent_object_id = colpar.object_id AND fkc.parent_column_id = colpar.column_id
INNER JOIN
sys.tables tref ON fk.referenced_object_id = tref.object_id
INNER JOIN
sys.columns colref ON fkc.referenced_object_id = colref.object_id AND fkc.referenced_column_id = colref.column_id
它会产生类似的输出:
FK Name Parent Table Parent Column Referenced Table Referenced Column Delete Action Update Action
这对我来说非常有效。随意适应您自己的需求。