Wednesday, March 7, 2012

Identity columns

Is there any simple query that returns identity column names in a database?This will do it:
select * from syscolumns where columnproperty(id, name, 'IsIdentity') = 1
"John" <anonymous@.discussions.microsoft.com> wrote in message
news:993EA3EB-2BEB-4BEE-B6F4-C36BF550011C@.microsoft.com...
> Is there any simple query that returns identity column names in a
database?|||John,
SELECT column_name AS 'Identity Column',table_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMNPROPERTY(OBJECT_ID(table_name),column_name,'IsIdentity') = 1
--
Dinesh
SQL Server MVP
--
--
SQL Server FAQ at
http://www.tkdinesh.com
"John" <anonymous@.discussions.microsoft.com> wrote in message
news:993EA3EB-2BEB-4BEE-B6F4-C36BF550011C@.microsoft.com...
> Is there any simple query that returns identity column names in a
database?

No comments:

Post a Comment