Wednesday, April 05, 2006

TSQL Script to Find All Identity Columns in a Database

select syscolumns.Name [Identity Column], sysobjects.Name [Table]
from syscolumns
inner join sysobjects on sysColumns.id = sysObjects.id
where autoval is not null


[Oh geeky joy!]

1 comment:

Jean E. said...

Here a version for SQL server 2005:

select distinct
so.Name [Table],
sc.Name [Identity Column]
from
sys.columns sc
inner join sys.objects so on sc.object_id = so.object_id
where
is_Identity = 1
order by
1

#Jean.