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.
| Author |
Topic |
|
ourspt
Starting Member
33 Posts |
Posted - 2005-05-16 : 07:16:22
|
| Hi,Is there any way, that I can determine whether a table has any identity column, programmatically in SQL Server. In other words, is it stored some where like syscolumns or sysconstraints or whatever, whether a table has identity column and what column has the identity property set to on? I am referring to SQL Server 2000.Thanks in advanceourspt |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2005-05-16 : 08:02:12
|
| [code]SELECT name AS TableName, CASE WHEN OBJECTPROPERTY(id,'TableHasIdentity') = 1 THEN 'TRUE' ELSE 'FALSE' END AS TableHasIdentityFROM sysobjectsWHERE xtype = 'U'[/code]MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2005-05-16 : 08:06:48
|
| [code]SELECT so.name AS TableName, sc.name AS ColumnNameFROM sysobjects so INNER JOIN syscolumns sc ON so.id = sc.idWHERE so.xtype = 'U' AND COLUMNPROPERTY(so.id, sc.name,'IsIdentity') = 1[/code]The first one will tell you if a table has an identity column. This one lists the table name and column name. That what you were wanting?MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2005-05-16 : 09:46:10
|
Using Sysobjects + Syscolumns = naughty You should be using the views provided by the very nice SQL development team at the Borg...errr.. Microsoft *need more coffee* |
 |
|
|
|
|
|