SQL Server CREATE DATABASE

Learning Objective

The objective of this tutorial is to teach you how to create a new database in SQL server using CREATE DATABASE statement or SQL Server Management Studio.

Introduction to CREATE DATABASE in SQL Server

The CREATE DATABASE statement is used to create a new database in SQL Server. You can create a database in SQL Server in two methods.

  1. Using T-SQL i.e. using CREATE DATABASE statement
  2. Using SQL Server Management Studio

Creating a new database in SQL Server using CREATE DATABASE statement

You can create new database by issuing CREATE DATABASE statement.

SQL Server CREATE DATABASE Syntax

The following is the syntax of SQL Server CREATE DATABASE statement.

CREATE DATABASE databasename;

In this syntax,

  • CREATE DATABASE – Keyword to create new database in SQL Server.
  • databasename – Name of the new database, you want to create in SQL Server.

Please note that you need to specify the databasename unique within the SQL Server instance.

SQL Server CREATE DATABASE Example

The below statement creates a new database named sampleDB.

CREATE DATABASE sampleDB;

Once the statement is completed successfully, you can check the name of the database using the below query which lists all the database name the SQL Server instance.

SELECT
   name
FROM
   sys.databases
ORDER BY
   name;

or you can execute one store procedure named sp_databases;

EXEC sp_databases;

Alternatively, you can check in the object explorer by reloading the object list by clicking the Refresh button or by pressing F5 in the keyboard.

SQL Server CREATE DATABASE

Creating a New Database Using SQL Server Management Studio

If you are more comfortable with the GUI, you can easily create a new database in SQL Server using SQL Server Management Studio.

First right-click on the Databases folder and click on New Database option as below.

SQL Server Create Database using SQL Server Management Studio

Now provide the name of the New database and click the OK button. In our case, we are giving TestDB as the new database name.

Finally, you can verify the name of the newly created database in the object explorer.

Summary

In this tutorial, you have learned how to create a new database in SQL Server using the CREATE DATABASE statement and SQL Server Management Studio.

Advertisement