Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Identity
Message
De
03/03/2003 16:12:40
 
 
À
03/03/2003 13:56:54
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Maintenance bases de données
Titre:
Divers
Thread ID:
00760462
Message ID:
00760520
Vues:
17
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform