Avatar of holemania
holemania

asked on 

SQL - Create database script with database name as parameter

I need help with a create script to create a blank new database.  How can I take the following script and create a parameter for database name so that it replace "DB1" with something I just have to type once as the parameter?  

USE [master]
GO
CREATE DATABASE [DB1] ON  PRIMARY
( NAME = N'DB1_Data', FILENAME = N'D:\Microsoft SQL Server\Data\DB1_Data.MDF' , SIZE = 78784KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%)
 LOG ON
( NAME = N'DB1_Log', FILENAME = N'D:\Microsoft SQL Server\Logs\DB1_log.ldf' , SIZE = 768KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%)
 COLLATE SQL_Latin1_General_CP1_CI_AS
GO
EXEC dbo.sp_dbcmptlevel @dbname=N'DB1', @new_cmptlevel=80
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [DB1].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO
ALTER DATABASE [DB1] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [DB1] SET ANSI_NULLS OFF
GO
ALTER DATABASE [DB1] SET ANSI_PADDING OFF
GO
ALTER DATABASE [DB1] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [DB1] SET ARITHABORT OFF
GO
ALTER DATABASE [DB1] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [DB1] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [DB1] SET AUTO_SHRINK ON
GO
ALTER DATABASE [DB1] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [DB1] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [DB1] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [DB1] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [DB1] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [DB1] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [DB1] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [DB1] SET  DISABLE_BROKER
GO
ALTER DATABASE [DB1] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [DB1] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [DB1] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [DB1] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [DB1] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [DB1] SET  READ_WRITE
GO
ALTER DATABASE [DB1] SET RECOVERY SIMPLE
GO
ALTER DATABASE [DB1] SET  MULTI_USER
GO
ALTER DATABASE [DB1] SET PAGE_VERIFY TORN_PAGE_DETECTION  
GO
ALTER DATABASE [DB1] SET DB_CHAINING OFF
GO
EXEC [DB1].sys.sp_addextendedproperty @name=N'NOTE', @value=N'TEST DATABASE'
SQL

Avatar of undefined
Last Comment
holemania
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Anuradha Goli
Anuradha Goli
Flag of Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of holemania
holemania

ASKER

Thank you.  I am out of the office this entire week and can't verify.  I will test it next week and get back.
Avatar of holemania
holemania

ASKER

Thank you.  That worked beautifully.
SQL
SQL

SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

61K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo