devxlogo

Determine Whether a Given Column Name Is an Identity or Not

Determine Whether a Given Column Name Is an Identity or Not

There are actually two ways in which you can find out whether a given column name is an identity or not in SQL Server:

  1. Method One:
    Select ColumnProperty(Object_id('Table_Name'), 'FieldName', 'IsIdentity')
  2. Method Two:
    Declare @colName varchar(100)Declare @RetColName varchar(100)Set @colName = 'FieldName' --Status column = 128 means its an identity columnSelect @RetColName=[name] from syscolumns where status=128 and id=(select idfrom sysobjects where name='Table_Name')If @colName = @RetColName   Print 'Its Identity'Else   Print 'Not an identity column'

See also  How College Students Can Shape the Future of Tech Responsibility
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist