Find identity columns on sqlserver

Sql script to list the columns for a given database that are acting as identity(auto-increment ) columns

The IDENTITY are  Auto Increment columns as some developers call them, are auto incrementing columns provided by SQL Server. There can only be one IDENTITY column per table. You just have to provide a base value, and an increment value, and SQL Server will take care of incrementing this column automatically. Some times you may have to find if certain table contains identity column or not. You can use script to list the ColumnName which is Identity column of a given database.

Sql script:

		
select * from sys.columns as c where c.is_identity=1 and object_id=(select object_id from sys.tables where name='TableName') 
blog comments powered by Disqus