To check whether a table already contains an identity column (mostly useful in change scripts), use the following sql code:


SELECT *
FROM information_schema.tables
WHERE table_name = 'your_table_name' AND
OBJECTPROPERTY(OBJECT_ID(TABLE_NAME), 'TableHasIdentity') = 0

Advertisements