Changes the database context to the specified database.
USE {database}
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.
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.
CREATE DATABASE | sp_adduser |
DROP DATABASE | sp_defaultdb |
EXECUTE | Using Identifiers |
sp_addalias |