USE [master]
GO


-- DROP LOGIN

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


-- DROP DATABASE

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


-- CREATE DATABASE

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

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

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

EXECUTE(@sql)
GO

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

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

ALTER DATABASE [VIGIL-POS] SET ANSI_NULL_DEFAULT OFF 
GO

ALTER DATABASE [VIGIL-POS] SET ANSI_NULLS OFF 
GO

ALTER DATABASE [VIGIL-POS] SET ANSI_PADDING OFF 
GO

ALTER DATABASE [VIGIL-POS] SET ANSI_WARNINGS OFF 
GO

ALTER DATABASE [VIGIL-POS] SET ARITHABORT OFF 
GO

ALTER DATABASE [VIGIL-POS] SET AUTO_CLOSE OFF 
GO

ALTER DATABASE [VIGIL-POS] SET AUTO_SHRINK OFF 
GO

ALTER DATABASE [VIGIL-POS] SET AUTO_UPDATE_STATISTICS ON 
GO

ALTER DATABASE [VIGIL-POS] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO

ALTER DATABASE [VIGIL-POS] SET CURSOR_DEFAULT  GLOBAL 
GO

ALTER DATABASE [VIGIL-POS] SET CONCAT_NULL_YIELDS_NULL OFF 
GO

ALTER DATABASE [VIGIL-POS] SET NUMERIC_ROUNDABORT OFF 
GO

ALTER DATABASE [VIGIL-POS] SET QUOTED_IDENTIFIER OFF 
GO

ALTER DATABASE [VIGIL-POS] SET RECURSIVE_TRIGGERS OFF 
GO

ALTER DATABASE [VIGIL-POS] SET  ENABLE_BROKER 
GO

ALTER DATABASE [VIGIL-POS] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO

ALTER DATABASE [VIGIL-POS] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO

ALTER DATABASE [VIGIL-POS] SET TRUSTWORTHY OFF 
GO

ALTER DATABASE [VIGIL-POS] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO

ALTER DATABASE [VIGIL-POS] SET PARAMETERIZATION SIMPLE 
GO

ALTER DATABASE [VIGIL-POS] SET READ_COMMITTED_SNAPSHOT OFF 
GO

ALTER DATABASE [VIGIL-POS] SET HONOR_BROKER_PRIORITY OFF 
GO

ALTER DATABASE [VIGIL-POS] SET RECOVERY SIMPLE 
GO

ALTER DATABASE [VIGIL-POS] SET  MULTI_USER 
GO

ALTER DATABASE [VIGIL-POS] SET PAGE_VERIFY CHECKSUM  
GO

ALTER DATABASE [VIGIL-POS] SET DB_CHAINING OFF 
GO

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

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

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


-- CREATE LOGIN

CREATE LOGIN [vpos] WITH PASSWORD = 0x02005559C95A46FFDC5C36587DB5CFEA884313BC29AFA4D303400E5ADEB44B5311EAFA09B24F95F2CEE1E7C0513E78BBC9486A4FF83082AEE88BB99BF0A93F59BBBFCFE08210 HASHED, DEFAULT_DATABASE=[VIGIL-POS], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO


-- CREATE USER

USE [VIGIL-POS]
GO

CREATE USER [vpos] FOR LOGIN [vpos]
GO

ALTER ROLE [db_owner] ADD MEMBER [vpos]
GO
