Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Finding identity column as primary key

Author  Topic 

hendrasd
Starting Member

20 Posts

Posted - 2003-04-01 : 01:45:23
Is there any procedures in SQL Server 2000 to find an identity column as primary key ?

-- Never stop learning --

nr
SQLTeam MVY

12543 Posts

Posted - 2003-04-01 : 03:36:06
declare @tblname varchar(128)
select @tblName = 'ss'
select c.name
from syscolumns c, INFORMATION_SCHEMA.TABLE_CONSTRAINTS i, INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ic
where c.id = object_id(@tblname)
and i.TABLE_NAME = @tblname
and ic.TABLE_NAME = @tblname
and i.CONSTRAINT_TYPE = 'PRIMARY KEY'
and i.CONSTRAINT_NAME = ic.CONSTRAINT_NAME
and ic.COLUMN_NAME = c.name

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -