views:

142

answers:

3

I want to do this in code, not with ALT+F1.

+4  A: 
sp_help tablename

In the output look for something like this:

 Identity     Seed     Increment     Not For Replication    
 -----------  -------  ------------  ---------------------- 
 userid       15500    1             0
Patrick McElhaney
Excellent answer! +1, short, yet accurate
sebastian
+2  A: 

Adjust the WHERE clause to suit:

select
    a.name as TableName,
    b.name as IdentityColumn
from
    sysobjects a inner join syscolumns b on a.id = b.id
where
    columnproperty(a.id, b.name, 'isIdentity') = 1
    and objectproperty(a.id, 'isTable') = 1
Luke Bennett
+6  A: 

You can also do it this way:

select columnproperty(object_id('mytable'),'mycolumn','IsIdentity')

Returns 1 if it's an identity, 0 if not.

Blorgbeard