SELECT f.name AS ForeignKeyName, OBJECT_NAME(f.parent_object_id) AS ReferencingTable, COL_NAME(fc.parent_object_id, fc.parent_column_id) AS ReferencingColumn, OBJECT_NAME (f.referenced_object_id) AS ReferencedTable, COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS ReferencedColumn FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.object_id = fc.constraint_object_id WHERE OBJECT_NAME (f.referenced_object_id) = 'pmw_house' ORDER BY ReferencingTable, ReferencingColumn;
當你嘗試截斷(TRUNCATE)一個資料庫表時,如果該表被其他表的 FOREIGN KEY 約束引用,你將無法執行該操作。這是因為截斷表會刪除表中的所有資料,並且通常也會重置表的身份標識(IDENTITY)值,這可能會破壞外來鍵引用的完整性。