Open In App

SQL CREATE DATABASE Statement

Last Updated : 18 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

To get started in SQL we need to create a new database. Only after creating a database can we perform actions in the database like adding tables and records. A database consists of tables in which we store the data or records.

SQL CREATE DATABASE

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

Important Points:

  • We have to type the database name after the CREATE DATABASE statement.
  • The database name is case-insensitive, so we need to create a unique database name.
  • Keep the limit of database names to 128 characters.

Syntax

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:

USE database_name

Key TakeAways About SQL CREATE DATABASE

In this article, we have learned how to create a new database in SQL.

  • A CREATE DATABASE statement is required to create a database.
  • A database consists of tables and inside the tables, we store the data.
  • Creating a new database is the first step in any SQL project and to create a new database in SQL we use the CREATE DATABASE command.

SQL CREATE DATABASE Statement – FAQs

How to delete a database?

To delete a database use DROP DATABASE command.

Can we create a table without creating a database?

No, as it is required to have a database first and inside a database only we can create tables.


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

Similar Reads