Open In App

SQL CREATE DATABASE

Last Updated : 08 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

SQL CREATE DATABASE statement creates a new database in SQL-based DBMS.

CREATE DATABASE in SQL

The CREATE DATABASE query in SQL is used to create a new database in the database management system. It is also used in MySQL and other relational database management systems (RDBMS) to create databases.

Syntax

The syntax to use the CREATE DATABASE command in SQL is:

CREATE DATABASE database_name;

CREATE DATABASE Examples

Let’s look at examples of how to create a database in SQL and how to verify database creation by listing databases in the server.

Creating Your First SQL Database

To create a new database in SQL we use the CREATE DATABASE command and then we mention the name of the database. Note that blank spaces are not allowed in the name of the database, we can only use underscore (_). 

As an example, we will create a new database with the name “GeeksForGeeks”.

SQL Query:

CREATE DATABASE GeeksForGeeks;

Output

creating new database

Creating a new database

Database Successfully Created!!

List Databases in SQL

Now we will verify whether the new database that we have just created has been successfully added to our system or not. 

We use the SHOW DATABASES command and it will return a list of databases that exist in our system. Now we will look for the name of the database (GeeksForGeeks) that we have just created.

SQL Query:

SHOW DATABASES;

Output

list of databases created

Database successfully created

As we can see the SHOW DATABASE command returned the list of all databases that exist in our system and in that list, the name of the database (GeeksForGeeks) that we have just created has also been added which verifies that the database has been successfully created.

USE Database in SQL

To use a specific database in SQL, we use the USE Statement.

Syntax

The syntax to use a database in SQL is:

USE database_name

Important Points About SQL CREATE DATABASE

  • A CREATE DATABASE statement is used to create a database.
  • A database consists of tables and inside the tables, we store the data.
  • The database name is case-insensitive, so we need to create a unique database name.
  • Keep the limit of database names to 128 characters.

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads