Is there a way to check if INDENTITY is enabled on a table?

Is there a way to check if INDENTITY is enabled on a table?

am 27.11.2007 18:44:06 von ck

Is there a way to check if INDENTITY is enabled on a table?

I want to provide a table name and see if Identity (Autonumber) is enabled
on it. Is this possible?

Thanks for any help.

Cheers,

~ck

Re: Is there a way to check if INDENTITY is enabled on a table?

am 27.11.2007 23:44:31 von Erland Sommarskog

CK (c_kettenbach@hotmail.com) writes:
> Is there a way to check if INDENTITY is enabled on a table?
>
> I want to provide a table name and see if Identity (Autonumber) is enabled
> on it. Is this possible?

There are several ways. The quickest is probably

SELECT CASE WHEN ident_current('tbl') IS NOT NULL
THEN 'Has identity'
ELSE 'Nope'
END

You can also use objectproperty, or look in sys.columns (SQL 2005 only).


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx