Tip of the Day : How to Read and Load an Excel 2007 or Excel 2010 File Without Using Import/Export Utility

SQL Server Helper - Tip of the Day

How to Determine if a Table Contains an IDENTITY Column

To determine if a table contains an IDENTITY column, run the following statement:

SELECT OBJECTPROPERTY(OBJECT_ID(N'[dbo].[Company]'), 
'TableHasIdentity')

A value of 1 means that the specified table has an IDENTITY column while a value of 0 means the table doesn’t have an IDENTITY column.  A value of NULL means either the table doesn’t exist or the object name passed is not a table.

To determine which column within a table is the IDENTITY column, run the following statement:

SELECT B.[Name] AS [IdentityColumn]
FROM [sys].[tables] A INNER JOIN [sys].[columns] B
  ON A.[Object_ID] = B.[Object_ID] AND
  A.[Name] = 'Company' AND
  COLUMNPROPERTY(A.[Object_ID], B.[Name], 'IsIdentity') = 1

Back to Tip of the Day List Next Tip