Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Identity
Message
From
03/03/2003 16:12:40
 
 
To
03/03/2003 13:56:54
General information
Forum:
Microsoft SQL Server
Category:
Database management
Title:
Miscellaneous
Thread ID:
00760462
Message ID:
00760520
Views:
18
Toni,

I don't think ALTER TABLE allows you to change an existing field to an identity column. However, you could do it in several steps. Something like this:
SELECT * INTO _Temp FROM YourTable WHERE 1=2 -- get an empty table with the same structure
ALTER TABLE _Temp DROP COLUMN nId -- remove existing Id
ALTER TABLE _Temp ADD nId int identity(1,1) -- add an identity column
SET IDENTITY_INSERT _Temp ON -- allow inserting explicit values into identity column

-- migrate existing data into temp table
INSERT INTO _Temp (nId, other fields...) SELECT nId, other fields... FROM YourTable
DROP TABLE YourTable -- drop original table
EXEC sp_rename '_Temp', 'YourTable' -- rename temp to original
HTH
>Hi everybody,
>
>I would like to modify existing field in database to field with identity on without using Enterprise manager.
>
>I would like to do something like this
>
>Alter TABLE alter column Identity
>
>
>Thanks for any suggestion,
>
>Toni
Daniel
Previous
Reply
Map
View

Click here to load this message in the networking platform