Auto-Select Database Name

  • 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?

  • You can put a use statement in the script.

    Use database1

    go

    Select statment

    Use database2

    go

    Select statement

  • 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.

  • 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

  • The command line was truncated:

    isqlw.exe -S SqlServerName -D DatabaseName

    SQL = Scarcely Qualifies as a Language

  • You can always change your default database to one you use the most...

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply