<分区>
Possible Duplicate:
In SQL server is there any way to get the 'use database' command to accept a variable
我们可以通过他们的名字来改变数据库是没有问题的
USE master
GO
但我需要在脚本中使用它并在变量中包含数据库名称。怎么做这个?
select @cmd = N'use ' + @oldDb + N';'
exec sp_executesql @cmd
那行不通 - 当前数据库在执行后保持不变。
有什么可能吗?