Summary: in this tutorial, you will learn how to create a new database in SQL Server using CREATE DATABASE
statement or SQL Server Management Studio.
Creating a new database using the CREATE DATABASE statement
The CREATE DATABASE
statement creates a new database. The following shows the minimal syntax of the CREATE DATABASE
statement:
CREATE DATABASE database_name;
In this syntax, you specify the name of the database after the CREATE DATABASE
keyword.
The database name must be unique within an instance of SQL Server. It must also comply with the SQL Server identifier’s rules. Typically, the database name has a maximum of 128 characters.
The following statement creates a new database named TestDb
:
CREATE DATABASE TestDb;
Code language: SQL (Structured Query Language) (sql)
Once the statement executes successfully, you can view the newly created database in the Object Explorer. If the new database does not appear, you can click the Refresh button or press F5 keyboard to update the object list.
This statement lists all databases in the SQL Server:
SELECT
name
FROM
master.sys.databases
ORDER BY
name;
Code language: SQL (Structured Query Language) (sql)
Or you can execute the stored procedure sp_databases
:
EXEC sp_databases;
Code language: SQL (Structured Query Language) (sql)
Creating a new database using SQL Server Management Studio
First, right-click the Database and choose New Database… menu item.
Second, enter the name of the database e.g., SampleDb and click the OK button.
Third, view the newly created database from the Object Explorer:
In this tutorial, you have learned how to create a new database using SQL Server CREATE DATABASE
statement and SQL Server Management Studio.