USE [master]
GO

-- DROP LOGIN

IF  EXISTS (SELECT * FROM sys.server_principals WHERE name = N'settings')
DROP LOGIN [settings]
GO


-- DROP DATABASE

IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'VIGIL-Settings')
DROP DATABASE [VIGIL-Settings]
GO


-- CREATE DATABASE

DECLARE @mdfFile nvarchar(260)
DECLARE @ldfFile nvarchar(260)
DECLARE @sql nvarchar(1024)

SELECT @mdfFile = replace([filename], [name], 'VIGIL_Settings') FROM sysfiles WHERE [filename] like '%.mdf'
SELECT @ldfFile = replace([filename], [name], 'VIGIL_Settings') FROM sysfiles WHERE [filename] like '%.ldf'

SET @sql = 'CREATE DATABASE [VIGIL-Settings]
	CONTAINMENT = NONE
	ON  PRIMARY 
	(NAME = N''VIGIL_Settings'', FILENAME = N'''+ @mdfFile + ''', SIZE = 6144KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB)
	LOG ON 
	(NAME = N''VIGIL_Settings_log'', FILENAME = N''' + @ldfFile + ''', SIZE = 1352KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)'

EXECUTE(@sql)
GO

ALTER DATABASE [VIGIL-Settings] SET COMPATIBILITY_LEVEL = 120
GO

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [VIGIL-Settings].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO

ALTER DATABASE [VIGIL-Settings] SET ANSI_NULL_DEFAULT OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET ANSI_NULLS OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET ANSI_PADDING OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET ANSI_WARNINGS OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET ARITHABORT OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET AUTO_CLOSE OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET AUTO_SHRINK OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET AUTO_UPDATE_STATISTICS ON 
GO

ALTER DATABASE [VIGIL-Settings] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET CURSOR_DEFAULT  GLOBAL 
GO

ALTER DATABASE [VIGIL-Settings] SET CONCAT_NULL_YIELDS_NULL OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET NUMERIC_ROUNDABORT OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET QUOTED_IDENTIFIER OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET RECURSIVE_TRIGGERS OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET  DISABLE_BROKER 
GO

ALTER DATABASE [VIGIL-Settings] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET TRUSTWORTHY OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET PARAMETERIZATION SIMPLE 
GO

ALTER DATABASE [VIGIL-Settings] SET READ_COMMITTED_SNAPSHOT OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET HONOR_BROKER_PRIORITY OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET RECOVERY SIMPLE 
GO

ALTER DATABASE [VIGIL-Settings] SET  MULTI_USER 
GO

ALTER DATABASE [VIGIL-Settings] SET PAGE_VERIFY CHECKSUM  
GO

ALTER DATABASE [VIGIL-Settings] SET DB_CHAINING OFF 
GO

ALTER DATABASE [VIGIL-Settings] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO

ALTER DATABASE [VIGIL-Settings] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO

ALTER DATABASE [VIGIL-Settings] SET DELAYED_DURABILITY = DISABLED 
GO


-- CREATE LOGIN

CREATE LOGIN [settings] WITH PASSWORD = 0x0200BF6C0DB36BF98649A4B300E2ADAF6F40D037C1DEDC30C45E7C97C27C768840234568437ED799AFAC2ADE6AE66AF0471807D50470E95174D957C72B8129F2622A5F091FEB HASHED, DEFAULT_DATABASE=[VIGIL-Settings], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO


-- CREATE USER

USE [VIGIL-Settings]
GO

CREATE USER [settings] FOR LOGIN [settings]
GO

ALTER ROLE [db_owner] ADD MEMBER [settings]
GO
