USE (T-SQL)

Changes the database context to the specified database.

Syntax

USE {database}

Arguments
database
Is the name of the database to which the user context is switched. Database names must conform to the rules for identifiers.
Remarks

USE executes at both compile and execution time and takes effect immediately. Therefore, statements that appear in a batch after the USE statement are executed in the specified database.

When logging in to Microsoft® SQL Server™, users are usually connected to the master database automatically. Unless a default database has been set up for each user’s login ID, each user must execute the USE statement to change from master to another database.

To change context to a different database, a user must have a security account for that database. The database owner provides the security accounts for the database.

Permissions

USE permissions default to those users who are assigned permissions by members of the db_owner fixed database role executing sp_adduser. Users without a security account in the destination database can still be allowed access if a guest user exists in that database.

See Also
CREATE DATABASE sp_adduser
DROP DATABASE sp_defaultdb
EXECUTE Using Identifiers
sp_addalias  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.