USE [master]
GO


-- DROP LOGIN

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


-- DROP DATABASE

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


-- CREATE DATABASE

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

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

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

EXECUTE(@sql)
GO

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

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

ALTER DATABASE [VIGIL-VA] SET ANSI_NULL_DEFAULT OFF 
GO

ALTER DATABASE [VIGIL-VA] SET ANSI_NULLS OFF 
GO

ALTER DATABASE [VIGIL-VA] SET ANSI_PADDING OFF 
GO

ALTER DATABASE [VIGIL-VA] SET ANSI_WARNINGS OFF 
GO

ALTER DATABASE [VIGIL-VA] SET ARITHABORT OFF 
GO

ALTER DATABASE [VIGIL-VA] SET AUTO_CLOSE OFF 
GO

ALTER DATABASE [VIGIL-VA] SET AUTO_SHRINK OFF 
GO

ALTER DATABASE [VIGIL-VA] SET AUTO_UPDATE_STATISTICS ON 
GO

ALTER DATABASE [VIGIL-VA] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO

ALTER DATABASE [VIGIL-VA] SET CURSOR_DEFAULT  GLOBAL 
GO

ALTER DATABASE [VIGIL-VA] SET CONCAT_NULL_YIELDS_NULL OFF 
GO

ALTER DATABASE [VIGIL-VA] SET NUMERIC_ROUNDABORT OFF 
GO

ALTER DATABASE [VIGIL-VA] SET QUOTED_IDENTIFIER OFF 
GO

ALTER DATABASE [VIGIL-VA] SET RECURSIVE_TRIGGERS OFF 
GO

ALTER DATABASE [VIGIL-VA] SET  DISABLE_BROKER 
GO

ALTER DATABASE [VIGIL-VA] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO

ALTER DATABASE [VIGIL-VA] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO

ALTER DATABASE [VIGIL-VA] SET TRUSTWORTHY OFF 
GO

ALTER DATABASE [VIGIL-VA] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO

ALTER DATABASE [VIGIL-VA] SET PARAMETERIZATION SIMPLE 
GO

ALTER DATABASE [VIGIL-VA] SET READ_COMMITTED_SNAPSHOT OFF 
GO

ALTER DATABASE [VIGIL-VA] SET HONOR_BROKER_PRIORITY OFF 
GO

ALTER DATABASE [VIGIL-VA] SET RECOVERY SIMPLE 
GO

ALTER DATABASE [VIGIL-VA] SET  MULTI_USER 
GO

ALTER DATABASE [VIGIL-VA] SET PAGE_VERIFY CHECKSUM  
GO

ALTER DATABASE [VIGIL-VA] SET DB_CHAINING OFF 
GO

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

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

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


-- CREATE LOGIN

CREATE LOGIN [va] WITH PASSWORD = 0x0200C54FF874013CEC11629503E30FE0FEB96A6D7307C9AFAFFC528E6C0BF462DD6D93EC92FE01A43CEF3332BAE5163E641F69687F551D5EE5DB1BB6E25A61D486D79C822F51 HASHED, DEFAULT_DATABASE=[VIGIL-VA], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO


-- CREATE USER

USE [VIGIL-VA]
GO

CREATE USER [va] FOR LOGIN [va]
GO

ALTER ROLE [db_owner] ADD MEMBER [va]
GO
