How to create database


SQL - Create Database 

A database is a structured collection of data that is organized in a way that allows for efficient storage, retrieval, and manipulation of information. In the realm of databases, SQL (Structured Query Language) plays a crucial role. SQL is a standard language used to interact with relational databases, enabling users to perform various operations such as querying data, updating records, and defining database structures

CREATE Database Statement

The CREATE DATABASE statement is a DDL (Data Definition Language) statement used to create a new database in SQL. If you are creating your database on Linux or Unix, then database names are case-sensitive, even though SQL keywords are case-insensitive. If you are working on Windows then this restriction does not apply.

Syntax

Following is the syntax to create a database in SQL -

CREATE DATABASE DatabaseName;

Here, the DatabaseName is the name of the database that we want to create. The database name can contain any valid identifiers, such as number, letters, or underscores. But a DatabaseName cannot be a keyword available in SQL.

Make sure you have admin privilege before creating any database. Once a database is created, you can check it in the list of databases with the following SQL command: SHOW DATABASES;

Example

Following is an example to create a database sample_DB using SQL CREATE DATABASE statement -

CREATE DATABASE sample_DB;

List Databases using SQL

Once the database sampl_DB is created, you can check it in the list of databases using SQL command SHOW DATABASES;.

Syntax

SHOW DATABASES;

Output

The output will be displayed as -

Database
master
performance_schema
information_schema
mysql
sample_DB

Use/Select Databases using SQL

We can now set the Sample_DB as the default database by using the USE statement in SQL.

Syntax

USE Sample_DB;

Great ! Now database is created , Now you can create SQL objects like function, table etc.

SQL - Create Database 

A database is a structured collection of data that is organized in a way that allows for efficient storage, retrieval, and manipulation of information. In the realm of databases, SQL (Structured Query Language) plays a crucial role. SQL is a standard language used to interact with relational databases, enabling users to perform various operations such as querying data, updating records, and defining database structures

CREATE Database Statement

The CREATE DATABASE statement is a DDL (Data Definition Language) statement used to create a new database in SQL. If you are creating your database on Linux or Unix, then database names are case-sensitive, even though SQL keywords are case-insensitive. If you are working on Windows then this restriction does not apply.

Syntax

Following is the syntax to create a database in SQL -

CREATE DATABASE DatabaseName;

Here, the DatabaseName is the name of the database that we want to create. The database name can contain any valid identifiers, such as number, letters, or underscores. But a DatabaseName cannot be a keyword available in SQL.

Make sure you have admin privilege before creating any database. Once a database is created, you can check it in the list of databases with the following SQL command: SHOW DATABASES;

Example

Following is an example to create a database sample_DB using SQL CREATE DATABASE statement -

CREATE DATABASE sample_DB;

List Databases using SQL

Once the database sampl_DB is created, you can check it in the list of databases using SQL command SHOW DATABASES;.

Syntax

SHOW DATABASES;

Output

The output will be displayed as -

Database
master
performance_schema
information_schema
mysql
sample_DB

Use/Select Databases using SQL

We can now set the Sample_DB as the default database by using the USE statement in SQL.

Syntax

USE Sample_DB;

Great ! Now database is created , Now you can create SQL objects like function, table etc.

Talk to us?

Post your blog