/*
CPXV2의 배포 스크립트

이 코드는 도구를 사용하여 생성되었습니다.
파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
변경 내용이 손실됩니다.
*/

GO
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;

SET NUMERIC_ROUNDABORT OFF;


GO
/*
:setvar DatabaseName "CPXV2"
:setvar DefaultFilePrefix "CPXV2"
:setvar DefaultDataPath ""
:setvar DefaultLogPath ""
*/

GO
:on error exit
GO
/*
SQLCMD 모드가 지원되지 않으면 SQLCMD 모드를 검색하고 스크립트를 실행하지 않습니다.
SQLCMD 모드를 설정한 후에 이 스크립트를 다시 사용하려면 다음을 실행합니다.
SET NOEXEC OFF; 
*/
:setvar __IsSqlCmdEnabled "True"
GO
IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
    BEGIN
        PRINT N'이 스크립트를 실행하려면 SQLCMD 모드를 사용하도록 설정해야 합니다.';
        SET NOEXEC ON;
    END


GO
USE [master];


GO

IF (DB_ID(N'$(DatabaseName)') IS NOT NULL) 
BEGIN
    ALTER DATABASE [$(DatabaseName)]
    SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    DROP DATABASE [$(DatabaseName)];
END

GO
PRINT N'$(DatabaseName) 데이터베이스를 만드는 중...'
GO
CREATE DATABASE [$(DatabaseName)] COLLATE Korean_Wansung_CI_AS
GO
USE [$(DatabaseName)];


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET ANSI_NULLS ON,
                ANSI_PADDING ON,
                ANSI_WARNINGS ON,
                ARITHABORT ON,
                CONCAT_NULL_YIELDS_NULL ON,
                NUMERIC_ROUNDABORT OFF,
                QUOTED_IDENTIFIER ON,
                ANSI_NULL_DEFAULT ON,
                CURSOR_DEFAULT LOCAL,
                RECOVERY SIMPLE,
                CURSOR_CLOSE_ON_COMMIT OFF,
                AUTO_CREATE_STATISTICS ON,
                AUTO_SHRINK OFF,
                AUTO_UPDATE_STATISTICS ON,
                RECURSIVE_TRIGGERS OFF 
            WITH ROLLBACK IMMEDIATE;
    END


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET ALLOW_SNAPSHOT_ISOLATION OFF;
    END


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET READ_COMMITTED_SNAPSHOT OFF 
            WITH ROLLBACK IMMEDIATE;
    END


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET AUTO_UPDATE_STATISTICS_ASYNC OFF,
                PAGE_VERIFY NONE,
                DATE_CORRELATION_OPTIMIZATION OFF,
                DISABLE_BROKER,
                PARAMETERIZATION SIMPLE,
                SUPPLEMENTAL_LOGGING OFF 
            WITH ROLLBACK IMMEDIATE;
    END


GO
IF IS_SRVROLEMEMBER(N'sysadmin') = 1
    BEGIN
        IF EXISTS (SELECT 1
                   FROM   [master].[dbo].[sysdatabases]
                   WHERE  [name] = N'$(DatabaseName)')
            BEGIN
                EXECUTE sp_executesql N'ALTER DATABASE [$(DatabaseName)]
    SET TRUSTWORTHY OFF,
        DB_CHAINING OFF 
    WITH ROLLBACK IMMEDIATE';
            END
    END
ELSE
    BEGIN
        PRINT N'데이터베이스 설정을 수정할 수 없습니다. 이러한 설정을 적용하려면 SysAdmin이어야 합니다.';
    END


GO
IF IS_SRVROLEMEMBER(N'sysadmin') = 1
    BEGIN
        IF EXISTS (SELECT 1
                   FROM   [master].[dbo].[sysdatabases]
                   WHERE  [name] = N'$(DatabaseName)')
            BEGIN
                EXECUTE sp_executesql N'ALTER DATABASE [$(DatabaseName)]
    SET HONOR_BROKER_PRIORITY OFF 
    WITH ROLLBACK IMMEDIATE';
            END
    END
ELSE
    BEGIN
        PRINT N'데이터베이스 설정을 수정할 수 없습니다. 이러한 설정을 적용하려면 SysAdmin이어야 합니다.';
    END


GO
ALTER DATABASE [$(DatabaseName)]
    SET TARGET_RECOVERY_TIME = 0 SECONDS 
    WITH ROLLBACK IMMEDIATE;


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET FILESTREAM(NON_TRANSACTED_ACCESS = OFF),
                CONTAINMENT = NONE 
            WITH ROLLBACK IMMEDIATE;
    END


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET AUTO_CREATE_STATISTICS ON(INCREMENTAL = OFF),
                MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT = OFF,
                DELAYED_DURABILITY = DISABLED 
            WITH ROLLBACK IMMEDIATE;
    END


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET QUERY_STORE (QUERY_CAPTURE_MODE = ALL, DATA_FLUSH_INTERVAL_SECONDS = 900, INTERVAL_LENGTH_MINUTES = 60, MAX_PLANS_PER_QUERY = 200, CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 367), MAX_STORAGE_SIZE_MB = 100) 
            WITH ROLLBACK IMMEDIATE;
    END


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET QUERY_STORE = OFF 
            WITH ROLLBACK IMMEDIATE;
    END


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 0;
        ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET MAXDOP = PRIMARY;
        ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = OFF;
        ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET LEGACY_CARDINALITY_ESTIMATION = PRIMARY;
        ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = ON;
        ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET PARAMETER_SNIFFING = PRIMARY;
        ALTER DATABASE SCOPED CONFIGURATION SET QUERY_OPTIMIZER_HOTFIXES = OFF;
        ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET QUERY_OPTIMIZER_HOTFIXES = PRIMARY;
    END


GO
IF EXISTS (SELECT 1
           FROM   [master].[dbo].[sysdatabases]
           WHERE  [name] = N'$(DatabaseName)')
    BEGIN
        ALTER DATABASE [$(DatabaseName)]
            SET TEMPORAL_HISTORY_RETENTION ON 
            WITH ROLLBACK IMMEDIATE;
    END


GO
IF fulltextserviceproperty(N'IsFulltextInstalled') = 1
    EXECUTE sp_fulltext_database 'enable';


GO
PRINT N'테이블 [dbo].[VRFY_TestListFileRelease]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[VRFY_TestListFileRelease] (
    [No]             BIGINT         IDENTITY (0, 1) NOT NULL,
    [TestListFileNo] INT            NULL,
    [StepID]         BIGINT         NOT NULL,
    [Variant]        NVARCHAR (32)  NOT NULL,
    [Gate]           NVARCHAR (128) NOT NULL,
    [Activate]       BIT            NULL,
    [StepVersion]    INT            NOT NULL,
    [Enable]         BIT            NULL,
    [Position]       BIGINT         NULL,
    [StepDesc]       NVARCHAR (512) NULL,
    [UseFunction]    NVARCHAR (256) NOT NULL,
    [MacroParm]      NVARCHAR (512) NULL,
    [Parm]           NVARCHAR (512) NULL,
    [SpecMin]        NVARCHAR (512) NOT NULL,
    [SpecMax]        NVARCHAR (512) NOT NULL,
    [IsGlobal]       BIT            NULL,
    [Dim]            NVARCHAR (64)  NOT NULL,
    [UpdateDT]       DATETIME2 (7)  NOT NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'인덱스 [dbo].[VRFY_TestListFileRelease].[CSK_VRFY_Release_2]을(를) 만드는 중...';


GO
CREATE NONCLUSTERED INDEX [CSK_VRFY_Release_2]
    ON [dbo].[VRFY_TestListFileRelease]([TestListFileNo] ASC, [StepID] ASC, [Enable] ASC, [No] ASC)
    ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[STOR_TestListFile]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[STOR_TestListFile] (
    [No]           INT             IDENTITY (0, 1) NOT NULL,
    [Name]         NVARCHAR (64)   NOT NULL,
    [TestType]     NVARCHAR (8)    NOT NULL,
    [Version]      NVARCHAR (4)    NOT NULL,
    [ProdCode]     NVARCHAR (4)    NOT NULL,
    [FileName]     NVARCHAR (64)   NOT NULL,
    [RegDT]        DATETIME2 (7)   NOT NULL,
    [RegUser]      NVARCHAR (32)   NOT NULL,
    [UpdateDT]     DATETIME2 (7)   NOT NULL,
    [UpdateUser]   NVARCHAR (32)   NOT NULL,
    [Comment]      NVARCHAR (256)  NULL,
    [Description]  NVARCHAR (256)  NULL,
    [TestListData] VARBINARY (MAX) NOT NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[STAT_User]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[STAT_User] (
    [No]       INT            IDENTITY (0, 1) NOT NULL,
    [UserID]   NVARCHAR (32)  NOT NULL,
    [Name]     NVARCHAR (32)  NOT NULL,
    [Password] NVARCHAR (32)  NOT NULL,
    [Dept]     NVARCHAR (64)  NOT NULL,
    [Email]    NVARCHAR (64)  NOT NULL,
    [Comment]  NVARCHAR (256) NULL,
    [UpdateDT] DATETIME2 (7)  NOT NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY],
    UNIQUE NONCLUSTERED ([UserID] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[STAT_TestCode]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[STAT_TestCode] (
    [No]       INT            IDENTITY (0, 1) NOT NULL,
    [TestCode] NVARCHAR (16)  NOT NULL,
    [Gate1]    NVARCHAR (64)  NOT NULL,
    [Gate2]    NVARCHAR (64)  NOT NULL,
    [Comment]  NVARCHAR (256) NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY],
    UNIQUE NONCLUSTERED ([TestCode] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[STAT_Host]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[STAT_Host] (
    [No]       INT            IDENTITY (0, 1) NOT NULL,
    [HostID]   NVARCHAR (64)  NOT NULL,
    [Section]  NVARCHAR (64)  NOT NULL,
    [IP]       NVARCHAR (15)  NOT NULL,
    [TestCode] NVARCHAR (16)  NULL,
    [Comment]  NVARCHAR (256) NULL,
    [UpdateDT] DATETIME2 (7)  NOT NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[PROD_Variant]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[PROD_Variant] (
    [No]             INT            IDENTITY (0, 1) NOT NULL,
    [ProdNo_P]       NVARCHAR (32)  NOT NULL,
    [RegDT]          DATETIME2 (7)  NOT NULL,
    [RegUser]        NVARCHAR (32)  NOT NULL,
    [UpdateDT]       DATETIME2 (7)  NOT NULL,
    [UpdateUser]     NVARCHAR (32)  NOT NULL,
    [GroupNo]        INT            NULL,
    [Comment]        NVARCHAR (256) NULL,
    [Description]    NVARCHAR (256) NULL,
    [TestListFileNo] INT            NULL,
    [UseTLPosition]  INT            NOT NULL,
    [IsUse]          BIT            NOT NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[PROD_Release]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[PROD_Release] (
    [No]             INT            IDENTITY (0, 1) NOT NULL,
    [ProdNo_C]       NVARCHAR (32)  NOT NULL,
    [TestCodeNo]     INT            NULL,
    [VariantNo]      INT            NULL,
    [Config]         NVARCHAR (32)  NOT NULL,
    [RegDT]          DATETIME2 (7)  NOT NULL,
    [RegUser]        NVARCHAR (32)  NOT NULL,
    [RegUserComment] NVARCHAR (256) NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[PROD_Group]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[PROD_Group] (
    [No]        INT            IDENTITY (0, 1) NOT NULL,
    [GroupName] NVARCHAR (128) NOT NULL,
    [ModelName] NVARCHAR (128) NOT NULL,
    [Comment]   NVARCHAR (256) NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY],
    UNIQUE NONCLUSTERED ([ModelName] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[HIST_TestListFileVariantList]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[HIST_TestListFileVariantList] (
    [No]             BIGINT          IDENTITY (0, 1) NOT NULL,
    [TestListFileNo] INT             NULL,
    [VariantList]    NVARCHAR (2048) NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'인덱스 [dbo].[HIST_TestListFileVariantList].[CSK_HIST_TestListFileVariantList_2]을(를) 만드는 중...';


GO
CREATE NONCLUSTERED INDEX [CSK_HIST_TestListFileVariantList_2]
    ON [dbo].[HIST_TestListFileVariantList]([TestListFileNo] ASC, [No] ASC)
    ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[HIST_TestListFileLatestStepVersion]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[HIST_TestListFileLatestStepVersion] (
    [No]                BIGINT IDENTITY (0, 1) NOT NULL,
    [TestListFileNo]    INT    NULL,
    [LatestStepVersion] INT    NOT NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[HIST_TestListFile]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[HIST_TestListFile] (
    [No]             BIGINT          IDENTITY (0, 1) NOT NULL,
    [TestListFileNo] INT             NULL,
    [Name]           NVARCHAR (64)   NOT NULL,
    [TestListData1]  VARBINARY (MAX) NULL,
    [TestListData2]  VARBINARY (MAX) NULL,
    [TestListData3]  VARBINARY (MAX) NULL,
    [TestListData4]  VARBINARY (MAX) NULL,
    [TestListData5]  VARBINARY (MAX) NULL,
    [TestListData6]  VARBINARY (MAX) NULL,
    [TestListData7]  VARBINARY (MAX) NULL,
    [TestListData8]  VARBINARY (MAX) NULL,
    [TestListData9]  VARBINARY (MAX) NULL,
    [TestListData10] VARBINARY (MAX) NULL,
    PRIMARY KEY CLUSTERED ([No] ASC) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY];


GO
PRINT N'인덱스 [dbo].[HIST_TestListFile].[CSK_HIST_TestList_2]을(를) 만드는 중...';


GO
CREATE NONCLUSTERED INDEX [CSK_HIST_TestList_2]
    ON [dbo].[HIST_TestListFile]([TestListFileNo] ASC, [Name] ASC, [No] ASC)
    ON [PRIMARY];


GO
PRINT N'테이블 [dbo].[HIST_TesterSummary]을(를) 만드는 중...';


GO
CREATE TABLE [dbo].[HIST_TesterSummary] (
    [No]                BIGINT         IDENTITY (0, 1) NOT NULL,
    [StationName]       NVARCHAR (128) NULL,
    [TestType]          NVARCHAR (8)   NOT NULL,
    [Version]           NVARCHAR (4)   NOT NULL,
    [ProdCode]          NVARCHAR (4)   NOT NULL,
    [TestListFileNo]    INT            NULL,
    [TestListVariantNo] INT            NULL,
    [TestListCntID]     NVARCHAR (256) NULL,
    [StepVersion]       INT            NULL,
    [HostID]            NVARCHAR (64)  NOT NULL,
    [Section]           NVARCHAR (64)  NOT NULL,
    [ProdNo_C]          NVARCHAR (32)  NOT NULL,
    [ProdNo_P]          NVARCHAR (32)  NOT NULL,
    [Testcode]          NVARCHAR (16)  NOT NULL,
    [TestListFileName]  NVARCHAR (256) NOT NULL,
    [ProductID]         NVARCHAR (64)  NOT NULL,
    [Result]            NVARCHAR (16)  NOT NULL,
    [Duration]          NVARCHAR (16)  NOT NULL,
    [TestDT]            DATETIME2 (7)  NOT NULL,
    UNIQUE NONCLUSTERED ([No] ASC) ON [PRIMARY]
) ON [PRIMARY];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[VRFY_TestListFileRelease]
    ADD DEFAULT ((1)) FOR [Activate];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[VRFY_TestListFileRelease]
    ADD DEFAULT ((1)) FOR [Enable];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[VRFY_TestListFileRelease]
    ADD DEFAULT ('') FOR [StepDesc];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[VRFY_TestListFileRelease]
    ADD DEFAULT ((0)) FOR [IsGlobal];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[VRFY_TestListFileRelease]
    ADD DEFAULT (getdate()) FOR [UpdateDT];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[STOR_TestListFile]
    ADD DEFAULT (getdate()) FOR [RegDT];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[STOR_TestListFile]
    ADD DEFAULT (getdate()) FOR [UpdateDT];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[STAT_User]
    ADD DEFAULT (getdate()) FOR [UpdateDT];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[STAT_Host]
    ADD DEFAULT (getdate()) FOR [UpdateDT];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Variant]
    ADD DEFAULT (getdate()) FOR [RegDT];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Variant]
    ADD DEFAULT (getdate()) FOR [UpdateDT];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Variant]
    ADD DEFAULT ((0)) FOR [UseTLPosition];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Variant]
    ADD DEFAULT ((1)) FOR [IsUse];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Release]
    ADD DEFAULT (getdate()) FOR [RegDT];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[HIST_TesterSummary]
    ADD DEFAULT ('-') FOR [StationName];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[HIST_TesterSummary]
    ADD DEFAULT ((-1)) FOR [TestListFileNo];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[HIST_TesterSummary]
    ADD DEFAULT ((-1)) FOR [TestListVariantNo];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[HIST_TesterSummary]
    ADD DEFAULT ((-1)) FOR [StepVersion];


GO
PRINT N'DEFAULT 제약 조건 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[HIST_TesterSummary]
    ADD DEFAULT (getdate()) FOR [TestDT];


GO
PRINT N'외래 키 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[VRFY_TestListFileRelease]
    ADD FOREIGN KEY ([TestListFileNo]) REFERENCES [dbo].[STOR_TestListFile] ([No]) ON DELETE SET NULL;


GO
PRINT N'외래 키 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Variant]
    ADD FOREIGN KEY ([GroupNo]) REFERENCES [dbo].[PROD_Group] ([No]) ON DELETE SET NULL;


GO
PRINT N'외래 키 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Variant]
    ADD FOREIGN KEY ([TestListFileNo]) REFERENCES [dbo].[STOR_TestListFile] ([No]) ON DELETE SET NULL;


GO
PRINT N'외래 키 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Release]
    ADD FOREIGN KEY ([TestCodeNo]) REFERENCES [dbo].[STAT_TestCode] ([No]) ON DELETE SET NULL;


GO
PRINT N'외래 키 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Release]
    ADD FOREIGN KEY ([VariantNo]) REFERENCES [dbo].[PROD_Variant] ([No]) ON DELETE SET NULL;


GO
PRINT N'외래 키 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[HIST_TestListFileVariantList]
    ADD FOREIGN KEY ([TestListFileNo]) REFERENCES [dbo].[STOR_TestListFile] ([No]) ON DELETE SET NULL;


GO
PRINT N'외래 키 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[HIST_TestListFileLatestStepVersion]
    ADD FOREIGN KEY ([TestListFileNo]) REFERENCES [dbo].[STOR_TestListFile] ([No]) ON DELETE SET NULL;


GO
PRINT N'외래 키 <이름 없음>을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[HIST_TestListFile]
    ADD FOREIGN KEY ([TestListFileNo]) REFERENCES [dbo].[STOR_TestListFile] ([No]) ON DELETE SET NULL;


GO
PRINT N'CHECK 제약 조건 [dbo].[CK_PROD_TestList_UseTLPosition_2]을(를) 만드는 중...';


GO
ALTER TABLE [dbo].[PROD_Variant]
    ADD CONSTRAINT [CK_PROD_TestList_UseTLPosition_2] CHECK (([UseTLPosition]>=(0) AND [UseTLPosition]<=(10)));


GO
PRINT N'프로시저 [dbo].[spGetDBList]을(를) 만드는 중...';


GO
CREATE PROCEDURE [dbo].[spGetDBList]
	
AS
	SELECT name FROM SYS.DATABASES WHERE name LIKE '%CPXV%'
RETURN 0
GO
/*
배포 후 스크립트 템플릿							
--------------------------------------------------------------------------------------
 이 파일에는 빌드 스크립트에 추가될 SQL 문이 있습니다.		
 SQLCMD 구문을 사용하여 파일을 배포 후 스크립트에 포함합니다.			
 예:      :r .\myfile.sql								
 SQLCMD 구문을 사용하여 배포 후 스크립트의 변수를 참조합니다.		
 예:      :setvar TableName MyTable							
               SELECT * FROM [$(TableName)]					
--------------------------------------------------------------------------------------
*/

--CPXV2 STAT_User 추가
INSERT INTO STAT_User (UserID, Name, Password, Dept, Email, Comment) VALUES ('Admin', 'Admin', 'Kefico!@34', 'Admin', 'systemx2051@gmail.com', 'Administrator');
GO

INSERT INTO STAT_User (UserID, Name, Password, Dept, Email, Comment) VALUES ('SystemX', 'SystemX', 'Kefico!@34', 'SystemX', 'systemx2051@gmail.com', 'SystemX');
GO

GO
DECLARE @VarDecimalSupported AS BIT;

SELECT @VarDecimalSupported = 0;

IF ((ServerProperty(N'EngineEdition') = 3)
    AND (((@@microsoftversion / power(2, 24) = 9)
          AND (@@microsoftversion & 0xffff >= 3024))
         OR ((@@microsoftversion / power(2, 24) = 10)
             AND (@@microsoftversion & 0xffff >= 1600))))
    SELECT @VarDecimalSupported = 1;

IF (@VarDecimalSupported > 0)
    BEGIN
        EXECUTE sp_db_vardecimal_storage_format N'$(DatabaseName)', 'ON';
    END


GO
ALTER DATABASE [$(DatabaseName)]
    SET MULTI_USER 
    WITH ROLLBACK IMMEDIATE;


GO
PRINT N'업데이트가 완료되었습니다.';


GO
