SQL create database statement is used to create a database with the specified name. Before you create tables and insert data into the tables, you need to create a database.
SQL Create Database Statement Syntax and Example:
CREATE DATABASE databaseName;
Here CREATE DATABASE is a keyword which needs to be written as it is, the
databaseName is the name of the database that you are creating with this statement. For example, to create a database Employee, you can write the create database statement like this:
CREATE DATABASE Employee;
This statement will create a database “Employee”, if the database doesn’t exist. On successful creation of the database, you will see the following output after executing above statement:
"Database created successfully"
Error, if database already exists
If a database with the name “Employee” is already present in the system, then this statement will throw the following error.
"Can't create database 'Employee'; database exists.
This is to avoid the duplication of database. A database name must be unique so if the database is already present with a specific name, you cannot create the database with the same name until you drop that existing database.
Verify whether database created successfully
You can verify the successful creation of database using show databases statement.
This statement, will list down all the databases that are present on the database system. You can easily check the database that you have created in the list to see whether the create database statement successfully created the database.
SQL> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | BeginnersBook | | AbcTemp | | Employee | | Customers | | Student | | Faculty | | MyTest | | Demo | +--------------------+ 8 rows in set (0.00 sec)
As you can see the SHOW DATABASES statement listed all the databases. You can also find the “Employee” database in the above list that we have created earlier using the
CREATE DATABASE statement.