Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Alter Table using argument?
Message
De
30/11/2005 14:02:01
 
 
À
30/11/2005 13:32:33
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01073290
Message ID:
01073363
Vues:
11
Thanks Keith!!

>>Without including all of the peripheral code, I am trying to do an ALTER TABLE command using an argument in a cursor. ALTER TABLE does not seem to like the argument. Any ideas??
>>
>> SET @KeyID = @TableName + '_KeyID'
>> ALTER TABLE @TableName ADD @KeyID INT IDENTITY(1,1) PRIMARY KEY NOT NULL
>
>Rollin,
>
>You have to use dynamic sql to use a variable as the object name:
>
>
>DECLARE @Sql nvarchar(4000)
>
>SET @KeyID = @TableName + '_KeyID'
>SET @Sql = N'ALTER TABLE ' + @TableName + ' ADD ' + @KeyID + ' INT IDENTITY(1,1) PRIMARY KEY NOT NULL'
>
>EXEC (@Sql)
>-- or EXEC sp_executesql @Sql
>
Thank You

Rollin Burr

Politicians and diapers have one thing in common. They should both be changed regularly, and for the same reason.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform