How to identify which column has the identity and get its details
Posted on 2003-03-24
Given the tablename i want to retrieve the NAME OF THE COLUMN having identity and then its details if possible.
I have found out so far 2 ways of doing it but i would like to go with a more effective way if possible
So far i have tried the following
a) sp_help tablename
This gives me the name of the identity column as well as its details which is exactly what i need but along with this it also returns number of other resultsets which are not needed.
b) By querying syscolumn and checking autoval column
This way is not documented. Documentation says that autoval column is for "internal use" but the value is usually set for identity columns, for other columns it is null.