我使用這個腳本查詢一些系統目錄視圖
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
這很好地爲我工作。隨意適應您自己的需求。
是的,但我想輸出它的可讀格式...我知道我可以應用自己的格式並編寫自己的代碼來完成所有這些,但似乎太麻煩了。 – matt