我有这个 t-sql 片段:
DECLARE @db_name varchar(255);
SET @db_name = 'MY_DATABASE'; -- assuming there is database called 'my_database'
USE @db_name -- this line ends with error "Incorrect syntax near '@db'."
但是 USE with variable (代码片段的第三行)不起作用。
为什么它不起作用?
最佳答案
您不能在变量中为 USE
语句提供数据库的名称。
关于sql-server-2005 - "USE @dbname"语句不起作用,为什么?怎么做?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2184219/