I'd like to create a dynamic ALTER TABLE and CURSOR based on a variable. Is
it possible ?If you really wanna do that dynamically by a Statement you should go for
that example which can be easily implemented in a trigger.
Create Table VarTestTable
(
COlumn1 INT
)
GO
DECLARE @.TableName varchar(50)
SET @.TableName = 'VarTestTable'
EXEC ('ALTER TABLE ' + @.TableName + ' ADD Column2 INT')
GO
Select * from VarTestTable
But beware of the curse of dynamic SQL :
http://www.sommarskog.se/dynamic_sql.html
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Jean Dupont" <Jean Dupont@.discussions.microsoft.com> schrieb im Newsbeitrag
news:F79E4618-EA42-44AC-9550-383E44EC0E67@.microsoft.com...
> I'd like to create a dynamic ALTER TABLE and CURSOR based on a variable.
> Is
> it possible ?|||Thank you. I didn't know what I did because I tried before to ask the
question and it didn't worked. But your very clear exemple is working very
well, even with cursors.
Thanks again.
"Jens Sü?meyer" a écrit :
> If you really wanna do that dynamically by a Statement you should go for
> that example which can be easily implemented in a trigger.
> Create Table VarTestTable
> (
> COlumn1 INT
> )
> GO
> DECLARE @.TableName varchar(50)
> SET @.TableName = 'VarTestTable'
> EXEC ('ALTER TABLE ' + @.TableName + ' ADD Column2 INT')
> GO
> Select * from VarTestTable
> But beware of the curse of dynamic SQL :
> http://www.sommarskog.se/dynamic_sql.html
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "Jean Dupont" <Jean Dupont@.discussions.microsoft.com> schrieb im Newsbeitr
ag
> news:F79E4618-EA42-44AC-9550-383E44EC0E67@.microsoft.com...
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment