SQL Server Tutorial SQL Server Advanced SQL Server Database SQL Server References

SQL Server - CREATE DATABASE



The SQL Server (Transact-SQL) CREATE DATABASE statement is used to create a new SQL Server database.

Syntax

The syntax of using CREATE DATABASE statement is given below:

CREATE DATABASE DatabaseName;

Please note that to create any database, admin privilege is required. Along with this, the database name should be unique within the RDBMS. After creating the database, the following command can be used to see the list of databases available in RDBMS.

SELECT name FROM sys.databases;

Example: create a database

To create a database with name testDB, the following query can be used:

CREATE DATABASE testDB;

After creating the database, the below mentioned command can be used to see the list of databases available in RDBMS.

SELECT name FROM sys.databases;
Result:
+-------------+
| name        |
+-------------+
| SQLExample1 |
| SQLExample2 |
| SQLExample3 |
| SQLExample4 |
| SQLExample5 |
| SQLExample6 |
| SQLExample7 |
| SQLExample8 |
| testDB      |
+-------------+

5