CREATE DATABASE statement is the SQL command used to create databases.
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;
CREATE DATABASEcommand creates a database
DB_NAMEis 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.
Here, the SQL command lists all the available databases in the DBMS.
We often have to work with multiple databases. To switch between available databases, we can run the following statement.
This code selects the my_db database, and all SQL operations will be performed inside this database.