Friday, April 11, 2008

How to list all the columns in the database which are used as identity key in my database?

How to list all the columns in the database which are used as identity key in my database?


Answer: Run following query in query editor.



USE AdventureWorks

GO


SELECT SCHEMA_NAME(schema_id) AS schema_name,
t.name AS table_name,
c.name AS column_name

FROM sys.tables AS t

JOIN sys.identity_columns c
ON t.OBJECT_ID = c.OBJECT_ID

ORDER BY schema_name, table_name;

GO

No comments: