Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

SQL - CREATE Database

he SQL CREATE DATABASE statement is used to create a new SQL database. If you are


creating your database on Linux or Unix, then database names are case-sensitive though SQL
keywords are case-insensitive. If you are working on Windows then this restriction does not
apply.

Syntax
The basic syntax of this CREATE DATABASE statement is as follows −
CREATE DATABASE DatabaseName;
Always the database name should be unique within the RDBMS.
While creating a database, you may encounter an error such as ERROR 1044 (42000): Access denied
for user 'krishna'@'localhost' to database 'DatabaseName', this means that you do not have the
necessary privileges to create a database.

Example
If you want to create a new database <testDB>, then the CREATE DATABASE statement would
be as shown below −
SQL> CREATE DATABASE testDB;
Make sure you have the necessary privilege before creating any database. Once a database is
created, you can check it in the list of databases as follows −
SQL> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| AMROOD |
| TUTORIALSPOINT |
| mysql |
| orig |
| test |
| testDB |
+--------------------+
7 rows in set (0.00 sec)
Once you have created a database, you can use it using the SQL USE statement as shown below:
SQL> USER testDB;
Database changed

You might also like