Identity Column in INFORMATION_SCHEMA or the sys tables

Identity Column in INFORMATION_SCHEMA or the sys tables

am 10.09.2007 16:13:57 von Wing9897

Hello,

Where can one find the identity column for a table in the
INFORMATION_SCHEMA or the sys tables? Or is there a function that can
return the name or id of the identity column for a particular table?
Thanks.

Re: Identity Column in INFORMATION_SCHEMA or the sys tables

am 10.09.2007 19:11:45 von kb

> Where can one find the identity column for a table in the
> INFORMATION_SCHEMA or the sys tables? Or is there a function that can
> return the name or id of the identity column for a particular table?

SELECT name
FROM sys.columns
WHERE object_id=OBJECT_ID('dbo.YourTableHere','U') AND is_identity=1


--
Tom
http://kbupdate.info/ | http://suppline.com/

Re: Identity Column in INFORMATION_SCHEMA or the sys tables

am 10.09.2007 19:15:48 von kb

>> Where can one find the identity column for a table in the
>> INFORMATION_SCHEMA or the sys tables? Or is there a function that can
>> return the name or id of the identity column for a particular table?
>
> SELECT name
> FROM sys.columns
> WHERE object_id=OBJECT_ID('dbo.YourTableHere','U') AND is_identity=1


SQL 7.0 / 2000 version:


SELECT name
FROM dbo.syscolumns
WHERE id=OBJECT_ID('dbo.YourTableHere','U') AND
COLUMNPROPERTY(id,name,'IsIdentity')=1


--
Tom
http://kbupdate.info/ | http://suppline.com/