Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine if a column is an identity column in MSSQL 2000?

I want to do this in code, not with ALT+F1.

like image 649
Bialecki Avatar asked Oct 09 '08 20:10

Bialecki


People also ask

How do you check if a column is identity or not?

Call this stored procedure using the datareader role, then check datareader. hasrows() . If the condition value is true ( 1 ), then the table has identity column if set. If not then it doesn't have an identity column.

How do I select an identity column in SQL Server?

We can use the SQL IDENTITY function to insert identity values in the table created by SQL SELECT INTO statement. By default, if a source table contains an IDENTITY column, then the table created using a SELECT INTO statement inherits it.

How do I make a column an identity column?

You cannot alter a column to be an IDENTITY column. What you'll need to do is create a new column which is defined as an IDENTITY from the get-go, then drop the old column, and rename the new one to the old name.


2 Answers

You can also do it this way:

select columnproperty(object_id('mytable'),'mycolumn','IsIdentity') 

Returns 1 if it's an identity, 0 if not.

like image 165
Blorgbeard Avatar answered Sep 25 '22 06:09

Blorgbeard


sp_help tablename  

In the output look for something like this:

 Identity     Seed     Increment     Not For Replication      -----------  -------  ------------  ----------------------   userid       15500    1             0         
like image 24
Patrick McElhaney Avatar answered Sep 25 '22 06:09

Patrick McElhaney