Pages

Monday, December 29, 2008

Identity Key columns in SQL Server

Use the below query to get all identity columns in the database.

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;

No comments: