Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Auto-Select Database Name Expand / Collapse
Author
Message
Posted Friday, July 4, 2008 8:39 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, October 8, 2014 6:30 AM
Points: 172, Visits: 62
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?
Post #528693
Posted Friday, July 4, 2008 8:49 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, May 9, 2013 8:07 AM
Points: 1,220, Visits: 2,614
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
Post #528699
Posted Friday, July 4, 2008 10:42 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 9:22 AM
Points: 1,116, Visits: 6,462
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.
Post #528726
Posted Friday, July 4, 2008 11:25 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 6:17 AM
Points: 2,281, Visits: 4,227
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
Post #528738
Posted Friday, July 4, 2008 11:27 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 6:17 AM
Points: 2,281, Visits: 4,227
The command line was truncated:
isqlw.exe -S SqlServerName -D DatabaseName



SQL = Scarcely Qualifies as a Language
Post #528739
Posted Friday, February 11, 2011 11:26 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, July 2, 2014 6:07 AM
Points: 227, Visits: 138
You can always change your default database to one you use the most...
Post #1062753
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse