0% found this document useful (0 votes)
5 views2 pages

SQL CREATE DATABASE Guide

The document explains how to create a database using SQL, specifically the CREATE DATABASE statement, which is a Data Definition Language (DDL) command. It outlines the syntax for creating a database, the case sensitivity of database names on different operating systems, and potential errors related to user privileges. Additionally, it describes how to list and select databases after creation using the SHOW DATABASES and USE statements.

Uploaded by

yeshrajpandey8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

SQL CREATE DATABASE Guide

The document explains how to create a database using SQL, specifically the CREATE DATABASE statement, which is a Data Definition Language (DDL) command. It outlines the syntax for creating a database, the case sensitivity of database names on different operating systems, and potential errors related to user privileges. Additionally, it describes how to list and select databases after creation using the SHOW DATABASES and USE statements.

Uploaded by

yeshrajpandey8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL - CREATE Database

A database is a structured collection of data that is stored in a computer system. They are used to
store and retrieve the data efficiently. Databases can be created using different query languages,
and SQL is one such language.

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.

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. To create a database, you
need to have admin previleges.

Example

Following is an example to create a database testDB using SQL CREATE DATABASE statement −

CREATE DATABASE testDB;


List Databases using SQL
Once the database testDB 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 −

Use/Select Databases using SQL


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

Syntax

USE testDB;

That's it! we have successfully created a database in SQL. Now, we can create tables and other
database objects within this new database.

You might also like