devxlogo

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'

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

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.