SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Auto-Select Database Name


Auto-Select Database Name

Author
Message
gillygilligan84
gillygilligan84
SSC Veteran
SSC Veteran (224 reputation)SSC Veteran (224 reputation)SSC Veteran (224 reputation)SSC Veteran (224 reputation)SSC Veteran (224 reputation)SSC Veteran (224 reputation)SSC Veteran (224 reputation)SSC Veteran (224 reputation)

Group: General Forum Members
Points: 224 Visits: 76
I have several databases to select from and each time I have to use the drop down menu to select the database I need. Is there any way of declaring which database I want to use without using the drop down menu?
KenSimmons
KenSimmons
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4738 Visits: 2614
You can put a use statement in the script.

Use database1
go
Select statment

Use database2
go
Select statement

Ken Simmons
http://twitter.com/KenSimmons
Clive Strong
Clive Strong
SSCertifiable
SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)

Group: General Forum Members
Points: 5422 Visits: 6652
Just qualify the database in the FROM clause.


SELECT Col1, Col2
FROM TestDB1.dbo.MyTable

SELECT Col5, Col10, Col7
FROM DifferentDB.dbo.AnotherTable

Run the queries and you'll be querying the databases without the need to change the database manually or use the USE syntax.
Carl Federl
Carl Federl
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14776 Visits: 4355
You can also create a shortcut to Query Analyzer that will automatically connect to a specific server and database. The command line is:

isqlw.exe -S

You can also add -E for Integrated Security or "-U -P" to hard code a login and password.

SQL = Scarcely Qualifies as a Language
Carl Federl
Carl Federl
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14776 Visits: 4355
The command line was truncated:

isqlw.exe -S SqlServerName -D DatabaseName



SQL = Scarcely Qualifies as a Language
k man
k man
Old Hand
Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)

Group: General Forum Members
Points: 327 Visits: 138
You can always change your default database to one you use the most...
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search