| title | Create a Database | |||
|---|---|---|---|---|
| description | Create a database in SQL Server by using SQL Server Management Studio or Transact-SQL. View recommendations for the procedure. | |||
| author | WilliamDAssafMSFT | |||
| ms.author | wiassaf | |||
| ms.reviewer | randolphwest | |||
| ms.date | 08/07/2025 | |||
| ms.service | sql | |||
| ms.subservice | configuration | |||
| ms.topic | how-to | |||
| helpviewer_keywords |
|
[!INCLUDE SQL Server]
This article describes how to create a database in [!INCLUDE ssnoversion] by using [!INCLUDE ssManStudioFull] or [!INCLUDE tsql].
To create a database in Azure SQL Database using T-SQL, see CREATE DATABASE.
A maximum of 32,767 databases can be specified on an instance of [!INCLUDE ssNoVersion].
The CREATE DATABASE statement must run in autocommit mode (the default transaction management mode) and isn't allowed in an explicit or implicit transaction.
The master database should be backed up whenever a user database is created, modified, or dropped.
When you create a database, make the data files as large as possible based on the maximum amount of data you expect in the database.
Requires CREATE DATABASE permission in the master database, or requires CREATE ANY DATABASE, or ALTER ANY DATABASE permission.
To maintain control over disk use on an instance of [!INCLUDE ssNoVersion], permission to create databases is typically limited to a few [!INCLUDE ssnoversion-md] logins.
-
In Object Explorer, connect to an instance of the [!INCLUDE ssDEnoversion] and then expand that instance.
-
Right-click Databases, and then select New Database.
-
In New Database, enter a database name.
-
To create the database by accepting all default values, select OK; otherwise, continue with the following optional steps.
-
To change the owner name, select (...) to select another owner.
[!NOTE]
The Use full-text indexing option is always checked and dimmed because all user databases are full-text enabled. -
To change the default values of the primary data and transaction log files, in the Database files grid, select the appropriate cell and enter the new value. For more information, see Add Data or Log Files to a Database.
-
To change the collation of the database, select the Options page, and then select a collation from the list.
-
To change the recovery model, select the Options page and select a recovery model from the list.
-
To change database options, select the Options page, and then modify the database options. For a description of each option, see ALTER DATABASE SET options (Transact-SQL).
-
To add a new filegroup, select the Filegroups page. Select Add and then enter the values for the filegroup.
-
To add an extended property to the database, select the Extended Properties page.
-
In the Name column, enter a name for the extended property.
-
In the Value column, enter the extended property text. For example, enter one or more statements that describe the database.
-
-
To create the database, select OK.
-
Connect to the [!INCLUDE ssDE].
-
From the Standard bar, select New Query.
-
Copy and paste the following example into the query window and select Execute. This example creates the database
Sales. Because the keywordPRIMARYisn't used, the first file (Sales_dat) becomes the primary file. BecauseMBorKBaren't specified in theSIZEparameter for theSales_datfile, it usesMBand is allocated in megabytes. TheSales_logfile is allocated in megabytes because theMBsuffix is explicitly stated in theSIZEparameter.
USE master;
GO
CREATE DATABASE Sales ON
(NAME = Sales_dat,
FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\saledat.mdf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5)
LOG ON
(NAME = Sales_log,
FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\salelog.ldf',
SIZE = 5 MB,
MAXSIZE = 25 MB,
FILEGROWTH = 5 MB);
GOFor more examples, see CREATE DATABASE.