您如何列出所有表格及其外文+;SQL查询中的主键?
有什么想法吗 这就是你要找的吗您如何列出所有表格及其外文+;SQL查询中的主键?,sql,sql-server,list,Sql,Sql Server,List,有什么想法吗 这就是你要找的吗 USE Database GO SELECT * FROM sys.tables WHERE type = 'PK' AND parent_object_id = OBJECT_ID ('sys.tables') GO 列出所有表和主键索引(如果存在)以及任何外键(以及FK引用的其他表)那么,问题是什么? SELECT TableName = t.Name, IndexName = I.Name, FKName = fk.Name,
USE Database
GO
SELECT * FROM sys.tables
WHERE type = 'PK' AND parent_object_id = OBJECT_ID ('sys.tables')
GO
列出所有表和主键索引(如果存在)以及任何外键(以及FK引用的其他表)那么,问题是什么?
SELECT
TableName = t.Name,
IndexName = I.Name,
FKName = fk.Name,
ReferencedTable = refT.Name
FROM
sys.tables t
LEFT OUTER JOIN
sys.indexes i ON i.object_id = t.object_id AND i.is_primary_key = 1
LEFT OUTER JOIN
sys.foreign_keys fk ON fk.parent_object_id = t.object_id
LEFT OUTER JOIN
sys.tables refT ON fk.referenced_object_id = refT.object_id
ORDER BY
t.Name, i.Name