The USE statement changes the current database context. After selecting a database, all SQL commands are executed inside that database until another database is selected.
A SQL Server may contain hundreds of databases. Selecting the correct database prevents accidental changes to the wrong application.
A developer creates a new database called HRManagement and then switches to it before creating tables.
USE HRManagement;
Database administrators and developers frequently switch between Development, Testing, and Production databases.
- Changes the current database.
- Does not create a database.
- Executed before creating tables.
- Helps avoid working in the wrong database.
- Only one database is active at a time.
- Commonly used after CREATE DATABASE.
- Available in SQL Server and MySQL.
What does the USE statement do?
It changes the current database context.
Does USE create a database?
No. It only selects an existing database.