MySQL - USE Statement



MySQL USE Statement

The USE statement of MySQL helps you to select/use a database. You can also change to another database with this statement. Once you set the current database it will be same until the end of the session unless you change the it.

Syntax

Following is the syntax of the MySQL USE statement −

USE db_name

Example

Following example demonstrates the usage of the MySQL USE statement −

use test;
CREATE TABLE SAMPLE(NAME VARCHAR(10));
INSERT INTO SAMPLE VALUES ('Raj');

use sample
Database changed

SELECT * FROM SAMPLE;
ERROR 1146 (42S02): Table 'sample.sample' doesn't exist

Example

Here we are creating a new database and changing the current database to it.

CREATE DATABASE myDatabase;
use myDatabase
Database changed
Advertisements