Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to code to set identity to ID column?

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2011-02-28 : 18:31:29
How to code to set identity to ID column?
I tried to set it in table design view but got time out error.
I set primary key for ID column successfully but need to set it "identity" on and increase by 1 using code.

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2011-02-28 : 23:08:56

quote:

I tried to set it in table design view but got time out error.



What is the error message ?

quote:

I set primary key for ID column successfully but need to set it "identity" on and increase by 1 using code.



Identity value increment automatically upon insertion of new row.
Go to Top of Page

mikgri
Starting Member

39 Posts

Posted - 2011-03-01 : 09:07:18
Open table in design view, change property of column to identity, do not save it.
On left upper corner of toolbox you will see icon "Generate Change Script", click to open it, copy and paste script to query window and run it.
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-01 : 09:40:42
I think there is no direct script through which you can change the existing column's property to Identity e.g. Alter Table .. Doing it via Design Mode results in sequence of steps at back end.


What you can do is to create another table with Identity Column as required and then insert the data from the original one into the newly create table via setting set identity_Insert property ...






Cheers
MIK
Go to Top of Page
   

- Advertisement -