Subin Benny Asked: 2022-09-22 22:58:41 +0800 CST2022-09-22 22:58:41 +0800 CST 2022-09-22 22:58:41 +0800 CST 如何查找具有自引用外键的表 772 嗨,是否有任何查询可以获取所有自引用外键。我需要通过雪橇引用获取数据库中的所有表和外键并删除并创建它。知道该怎么做吗? sql-server database-design 1 个回答 Voted Best Answer Zikato 2022-09-22T23:12:28+08:002022-09-22T23:12:28+08:00 您可以使用 DMV - 更具体地说是sys.foreign_keys SELECT fk.object_id AS FkId , fk.name AS FkName , fk.parent_object_id AS TableId , OBJECT_NAME(fk.parent_object_id) AS TableName FROM sys.foreign_keys AS fk WHERE fk.referenced_object_id = fk.parent_object_id
您可以使用 DMV - 更具体地说是sys.foreign_keys