且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在sql server中找到循环依赖表

更新时间:2023-01-22 09:14:24

您真的不需要购买工具才能找到这些参考。

  SELECT 
OBJECT_SCHEMA_NAME(fk1.parent_object_id)
+'。'+ OBJECT_NAME(fk1.parent_object_id),
OBJECT_SCHEMA_NAME(fk2.parent_object_id)
+'。'+ OBJECT_NAME(fk2.parent_object_id )
FROM sys.foreign_keys AS fk1
INNER JOIN sys.foreign_keys AS fk2
ON fk1.parent_object_id = fk2.referenced_object_id
AND fk2.parent_object_id = fk1.referenced_object_id;


Currently im working on finding the dpendency order of tables in a database. And im stuck up with peoblem of circular depedency of some tables in database.

since some tables are circularly depended im not getting the entire order.....

Is there any way to find circular dependent tables in any database in sql server, Other than the database diagrams??

You don't really need to buy a tool to find these references.

SELECT 
  OBJECT_SCHEMA_NAME(fk1.parent_object_id)
   + '.' + OBJECT_NAME(fk1.parent_object_id), 
  OBJECT_SCHEMA_NAME(fk2.parent_object_id)
   + '.' + OBJECT_NAME(fk2.parent_object_id)
FROM sys.foreign_keys AS fk1
INNER JOIN sys.foreign_keys AS fk2
ON fk1.parent_object_id = fk2.referenced_object_id
AND fk2.parent_object_id = fk1.referenced_object_id;