I want to do this in code, not with ALT+F1.
I want to do this in code, not with ALT+F1.
You can also do it this way:
select columnproperty(object_id('mytable'),'mycolumn','IsIdentity')
Returns 1 if it's an identity, 0 if not.
sp_help tablename
In the output look for something like this:
Identity Seed Increment Not For Replication
----------- ------- ------------ ----------------------
userid 15500 1 0
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
Identity is the value that is used for the very first row loaded into the table.
There is a microsoft article which can provide good knowledge about Identity:
Now, there are couple of ways for identifying which column is an identity column in a table: