SQL Server Tutorial SQL Server Advanced SQL Server Database SQL Server References

SQL Server - SELECT DATABASE



When there are multiple databases in the SQL Server (Transact-SQL) Schema, then before starting any operation on a given database, that database need to be selected. The SQL Server (Transact-SQL) USE statement is used to select any existing database in the SQL Server (Transact-SQL) schema.

Syntax

The syntax of selecting database is given below:

USE DatabaseName;

To see the list of databases available in RDBMS, the following command can be used:

SHOW DATABASES;

Example: Select a database

To select a database with name testDB, the following query can be used:

USE testDB;

To check all the available datasets, SHOW DATABASES; command can be used:

SQL Server > SHOW DATABASES;
+-------------+
| Database    |
+-------------+
| SQLExample1 |
| SQLExample2 |
| SQLExample3 |
| SQLExample4 |
| SQLExample5 |
| SQLExample6 |
| SQLExample7 |
| SQLExample8 |
| testDB      |
+-------------+
9 rows in set (0.00 sec)

5