Find identity columns on sqlserver

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.

Code:

select * from sys.columns as c where c.is_identity=1 and object_id=(select object_id from sys.tables where name='TableName')
, ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Share to Facebook Share to Twitter Stumble It Share on Tumblr Digg More...