2008-04-06

Retrieving identity columns information for tables in an SQL Server database

SELECT OBJECT_NAME(OBJECT_ID) AS [TABLE_NAME],
[NAME] AS [COLUMN_NAME],
[SEED_VALUE],
[INCREMENT_VALUE],
[LAST_VALUE],
[IS_NOT_FOR_REPLICATION]
FROM [SYS].[IDENTITY_COLUMNS]
ORDER BY [TABLE_NAME]

The result is a table with the following structure (column names shortened for space):


TNCNSVIVLVINF
TableNameKeyColumn11NULL0
TableName2KeyColumn211NULL0

No comments: