语句“USE @dbname"不起作用,为什么?怎么做? [英] statement "USE @dbname" doesn't work, why? How to do that?
本文介绍了语句“USE @dbname"不起作用,为什么?怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个 t-sql 片段:
I've got this t-sql snippet:
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'."
但是使用变量(代码段的第三行)不起作用.为什么它不起作用?
But USE with variable (third line of snippet) doesn't work. Why it doesn't work?
推荐答案
您不能在变量中为 USE
语句提供数据库的名称.
You cannot provide the name of the database for USE
statement in a variable.
这篇关于语句“USE @dbname"不起作用,为什么?怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文