Roman Rehak

SQL Server and things not related

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567


Navigation

SQL Server Sites

Subscriptions

News

eXTReMe Tracker

Post Categories



Tuesday, April 19, 2005 - Posts

Roman's Weekly SQL Server Tip - How to determine whether the table has an identity column in code

I had to do this recently in one of my utility stored procedures so I thought it would make a good tip. If you need to programatically determine whether the table has an identity column, you can use the OBJECTPROPERTY function and ask for the value of the 'TableHasIdentity' property:

SELECT OBJECTPROPERTY(object_id('MyTable'), 'TableHasIdentity')

SQL Server returns 1 if the table has an identity column, 0 if it doesn't.

posted Tuesday, April 19, 2005 8:58 PM by Roman with 699 Comments




Powered by Dot Net Junkies, by Telligent Systems