Identity Column in INFORMATION_SCHEMA or the sys tables

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.
Wing9897 [ Mo, 10 September 2007 16:13 ] [ ID #1816531 ]

Re: Identity Column in INFORMATION_SCHEMA or the sys tables

> 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/
kb [ Mo, 10 September 2007 19:11 ] [ ID #1816536 ]

Re: Identity Column in INFORMATION_SCHEMA or the sys tables

>> 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/
kb [ Mo, 10 September 2007 19:15 ] [ ID #1816537 ]
Datenbanken » comp.databases.ms-sqlserver » Identity Column in INFORMATION_SCHEMA or the sys tables

Vorheriges Thema: INNER JOIN - INSERT
Nächstes Thema: CREATE TABLE syntax error...