# Create SQL Server Database

In 
Published 2022-12-03

This tutorial explains to you how to create a SQL Server database. This article has a step-by-step approach.

Here are the steps for creating a SQL Server database using the SQL Server Management Studio:

Click on "Database" -> Right Click on "New Database".

Enter the name of the new database, the owner of the database and the database files (data & log files).

Click on "Options" and modify or let the default values.

Click on "Filegroup" in order to add filegroups and click on "OK". A new database will be created.

And here is the new SQL Server database created in SQL Server Management Studio.

Here is the code for creating this SQL Server database:

USE [master]
GO
 
CREATE DATABASE [mydatabase]
 CONTAINMENT = NONE
 ON  PRIMARY
( NAME = N'mydatabase', 
  FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\mydatabase.mdf' , 
  SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
 LOG ON
( NAME = N'mydatabase_log', 
  FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\mydatabase_log.ldf' , 
  SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
GO
 
ALTER DATABASE [mydatabase] SET COMPATIBILITY_LEVEL = 130
GO
 
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [mydatabase].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
 
ALTER DATABASE [mydatabase] SET ANSI_NULL_DEFAULT OFF
GO
 
ALTER DATABASE [mydatabase] SET ANSI_NULLS OFF
GO
 
ALTER DATABASE [mydatabase] SET ANSI_PADDING OFF
GO
 
ALTER DATABASE [mydatabase] SET ANSI_WARNINGS OFF
GO
 
ALTER DATABASE [mydatabase] SET ARITHABORT OFF
GO
 
ALTER DATABASE [mydatabase] SET AUTO_CLOSE OFF
GO
 
ALTER DATABASE [mydatabase] SET AUTO_SHRINK OFF
GO
 
ALTER DATABASE [mydatabase] SET AUTO_UPDATE_STATISTICS ON
GO
 
ALTER DATABASE [mydatabase] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
 
ALTER DATABASE [mydatabase] SET CURSOR_DEFAULT  GLOBAL
GO
 
ALTER DATABASE [mydatabase] SET CONCAT_NULL_YIELDS_NULL OFF
GO
 
ALTER DATABASE [mydatabase] SET NUMERIC_ROUNDABORT OFF
GO
 
ALTER DATABASE [mydatabase] SET QUOTED_IDENTIFIER OFF
GO
 
ALTER DATABASE [mydatabase] SET RECURSIVE_TRIGGERS OFF
GO
 
ALTER DATABASE [mydatabase] SET  DISABLE_BROKER 
GO
 
ALTER DATABASE [mydatabase] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
 
ALTER DATABASE [mydatabase] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
 
ALTER DATABASE [mydatabase] SET TRUSTWORTHY OFF
GO
 
ALTER DATABASE [mydatabase] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
 
ALTER DATABASE [mydatabase] SET PARAMETERIZATION SIMPLE 
GO
 
ALTER DATABASE [mydatabase] SET READ_COMMITTED_SNAPSHOT OFF
GO
 
ALTER DATABASE [mydatabase] SET HONOR_BROKER_PRIORITY OFF
GO
 
ALTER DATABASE [mydatabase] SET RECOVERY SIMPLE 
GO
 
ALTER DATABASE [mydatabase] SET  MULTI_USER 
GO
 
ALTER DATABASE [mydatabase] SET PAGE_VERIFY CHECKSUM  
GO
 
ALTER DATABASE [mydatabase] SET DB_CHAINING OFF
GO
 
ALTER DATABASE [mydatabase] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
 
ALTER DATABASE [mydatabase] SET TARGET_RECOVERY_TIME = 60 SECONDS 
GO
 
ALTER DATABASE [mydatabase] SET DELAYED_DURABILITY = DISABLED 
GO
 
ALTER DATABASE [mydatabase] SET QUERY_STORE = OFF
GO
 
USE [mydatabase]
GO
 
ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 0;
GO
 
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET MAXDOP = PRIMARY;
GO
 
ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = OFF;
GO
 
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET LEGACY_CARDINALITY_ESTIMATION = PRIMARY;
GO
 
ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = ON;
GO
 
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET PARAMETER_SNIFFING = PRIMARY;
GO
 
ALTER DATABASE SCOPED CONFIGURATION SET QUERY_OPTIMIZER_HOTFIXES = OFF;
GO
 
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET QUERY_OPTIMIZER_HOTFIXES = PRIMARY;
GO
 
ALTER DATABASE [mydatabase] SET  READ_WRITE 
GO