我需要编写一个查询,该查询将返回所有具有主键列但未将标识规范或(是标识)设置为是的表。
任何人都可以帮助我
答案 0 :(得分:1)
不是最干净但它应该有用。
SELECT cu.TABLE_NAME,COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu
INNER JOIN sys.Tables t ON cu.TABLE_NAME = t.Name
INNER JOIN sys.Columns c ON t.object_id = c.object_id AND cu.COLUMN_NAME = c.Name
WHERE OBJECTPROPERTY(OBJECT_ID(CONSTRAINT_SCHEMA + '.' + CONSTRAINT_NAME), 'IsPrimaryKey') = 1
AND is_identity = 0