use

Specifies the database with which you want to work.

Syntax

use database_name 

Parameters

Examples

Usage

  • Allowed with an archive database.

  • The use command must be executed before you can reference objects in a database.

  • use cannot be included in a stored procedure or a trigger.

  • sp_addalias adds an alias, which permits a user to use a database under another name to gain access to that database.

See also sp_addalias and sp_adduser in Reference Manual: Procedures.

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

The permission checks for use differ based on your granular permissions settings.

SettingDescription
Enabled

With granular permissions diabled, you must be a valid, alias, or guest user, or, a user with own database privilege or use database privilege on the database.

If the database has a guest account, all users can use the database. If the database does not have a guest account, you must be a valid user in the database, have an alias in the database, or have own database privilege or use database privilege on the database.

Disabled

With granular permissions diabled, you must be a valid, alias, or guest user, or, a user with sa_role or sso_role.

If the database has a “guest” account, all users can use the database. If the database does not have a “guest” account, you must be a valid user in the database, have an alias in the database, or be a system administrator or system security officer.

Related reference
create database
drop database