Choosing a Database: USE

When you log in to SQL Server, you are placed into a default database (initially the master database unless otherwise specified by the system administrator). Many tools also let you specify which database to use. For example, with the pubs sample database, even if your default database is master you can use:

isql /Usa /dpubs

where

d is the database option switch.

To switch to another database, from the SQL Enterprise Manager Query window, select the database to switch to from the DB drop-down list.

Or you can use the USE statement:

USE database_name

The USE statement changes the current database context to the specified database. For example, to switch to pubs, type:

USE pubs

Note The examples in this chapter are based on the pubs sample database.

Once you have selected a database, you are ready to build a query using the SELECT statement.