开发者

How do I switch to a SQL Server Server Database that will exist after another command?

开发者 https://www.devze.com 2022-12-29 01:13 出处:网络
I can\'t get this script to run, because SQL management studio 2008 says the table \"NewName\" does not exist. However, the script\'s purpose 开发者_运维百科is to rename an existing database, so that

I can't get this script to run, because SQL management studio 2008 says the table "NewName" does not exist. However, the script's purpose 开发者_运维百科is to rename an existing database, so that it does exist when it gets to that line. Ideas?

Use Master;

ALTER DATABASE OldName SET SINGLE_USER WITH NO_WAIT;
ALTER DATABASE OldName MODIFY NAME = NewName;

ALTER DATABASE NewName SET MULTI_USER;
Use NewName; --THIS LINE FAILS BEFORE THE SCRIPT EVEN RUNS!


Add GO between the 2nd and 3rd ALTER DATABASE statements.

http://msdn.microsoft.com/en-us/library/ms188037.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消