W3Basic Logo

SQL Server CREATE DATABASE

We can Create a new Database in the SQL using the CREATE DATABASE statement. Creating the database is the most important step before we start working with the database.


Let us learn how to create a new database in SQL with examples.

Syntax of Create Database

The Syntax for creating a new Database in SQL is

CREATE DATABASE DB_NAME

We need to provide the Database name that we would like to create for the CREATE DATABASE SQL statement.

Rules for Creating Database in SQL

There are a few basic guidelines you need to follow while creating a new database in SQL.

  1. The database name should be unique. If there is already a database with the same name then SQL will throw an error while creating the database.

  2. The Database name must always start with a valid letter.

  3. The database name should only consist of letters [a-z, A-Z] (both uppercase and lowercase), underscore ( _ ), and hyphen ( - ).

  4. The Database name cannot exceed 128 characters.

Example: Creating Database in SQL

In the following example, we are creating a new database called “Employee” using the CREATE DATABASE SQL statement.

CREATE DATABASE Employee

Output

When we execute the above query the database gets created and shows the following output.

Commands completed successfully.

We can verify if the database is created in SQL using the following query. The SHOW DATABASES query will list all the databases in the system.

SELECT 
  name 
FROM 
  sys.databases 
ORDER BY 
  name;

Output

AdventureWorks
Employee
master
model
msdb
tempdb
Test

Note: If we try to create the database with the same name again, we will get an error message as shown below.

CREATE DATABASE Employee

Output

Database 'Employee' already exists. Choose a different database name.

© 2023 W3Basic. All rights reserved.

Follow Us: