如何创建一个查询,为我提供 SQL Server 中具有复合主键的表列表?也许使用 sys.tables 或 information_schema.tables 或其他东西?
你可以挖掘这些信息information_schema.table_constraints
and information_schema.constraint_column_usage
表,通过检查多行PRIMARY KEY
表上的约束,例如:
SELECT col.table_name
FROM information_schema.table_constraints tc
JOIN information_schema.constraint_column_usage col
ON col.constraint_name = tc.constraint_name
AND col.table_name = tc.table_name
AND tc.constraint_type = 'PRIMARY KEY'
GROUP BY col.table_name
HAVING COUNT(*) > 1
用于测试的 SQLfiddle http://sqlfiddle.com/#!3/b1162/1.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)