Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How do you select a database

Author  Topic 

sonial8
Starting Member

5 Posts

Posted - 2009-11-02 : 14:30:07
I have a sql query script and a number of databases i.e. master, DB1, DB2, etc.

So, If I want the saved script to choose DB2 and then run the various commands how do I do this?

I receive an error if I try select database DB2

Thanks in advance.


sonia

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-02 : 14:30:58
USE db1
GO
...
...
USE db2
GO
...
...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

sonial8
Starting Member

5 Posts

Posted - 2009-11-02 : 16:48:23
Thank you this works.

sonia
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-02 : 17:33:10
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -