Ever need to know all the identity fields in a database? With a current project I am working on (having to do with replication) I need to know every identity field there is in a database (and of course what tables they are in) ... so since all this information is stored in
SYSCOLUMNS and
SYSOBJECTS, just query them like this:
SELECT o.name AS TableName, c.name AS ColumName
FROM syscolumns c JOIN sysobjects o
ON c.id = o.id
WHERE c.status = 128 -- 0x80 is an identity column
ORDER BY o.name, c.name