The CREATE DATABASE
statement is the SQL command used to create databases.
Example
CREATE DATABASE my_db;
Here, the SQL command creates a database named my_db.
SQL CREATE DATABASE Syntax
The syntax of the SQL CREATE DATABASE
statement is:
CREATE DATABASE DB_NAME;
Here,
CREATE DATABASE
command creates a databaseDB_NAME
is the name of the database created
CREATE DATABASE IF NOT EXISTS
If a database already exists, SQL will throw an error while creating another database of the same name.
In such situations, we can use the CREATE DATABASE IF NOT EXISTS
statement to create a database only if there is no existing database with the same name. For example,
CREATE DATABASE IF NOT EXISTS my_db;
Here, the SQL command creates a database named my_db only if there is no existing database with the same name.
List all Databases
There could be multiple databases in a database management system. To show the list of databases, we can run the following statement.
SHOW DATABASES;
Here, the SQL command lists all the available databases in the DBMS.
Switch Databases
We often have to work with multiple databases. To switch between available databases, we can run the following statement.
USE my_db;
This code selects the my_db database, and all SQL operations will be performed inside this database.
Recommended Reading