Monday 22 April 2013

Get the List of Tables and Column having the Identity Field or Column

To get the list of tables having identity columns, we can use the INFORMATION_SCHEMA view of the SQL Server. Below is the script:

selectCOLUMN_NAME, TABLE_NAME
from
INFORMATION_SCHEMA.COLUMNS
whereTABLE_SCHEMA = 'dbo'
andCOLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1
order
by TABLE_NAME