0

我在 中调用CustomerID了一个主键,CustomerTable并且此 PK 有可能在同一数据库中的各种其他表(读取超过 50 个)中用作 FK。

我想知道是否有一种简单的方法可以识别此 PK 被用作 FK 的所有表。

注意:我使用的是 SQL Server

任何帮助将不胜感激

4

2 回答 2

2
SELECT ro.name as Referedtable, co.name as foreinKey,so.name as ParentTable
FROM sys.foreign_key_columns fkc
join sys.sysobjects co on co.id=fkc.constraint_object_id
join sys.sysobjects so on so.id=fkc.parent_object_id
join sys.sysobjects ro on ro.id=fkc.referenced_object_id
where ro.name='CustomerTable'
于 2013-02-27T17:08:27.110 回答
0

I figured this out by myself and here's what I did.

SELECT *
  FROM [YourDBName].[sys].[foreign_keys]
  WHERE name LIKE '%CustomerID%' 
于 2013-02-27T17:10:27.750 回答