﻿/*
Deployment script for C2P_prod

This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
*/

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

SET NUMERIC_ROUNDABORT OFF;


GO
:setvar DatabaseName "C2P"
:setvar DefaultFilePrefix "C2P_prod"
:setvar DefaultDataPath "G:\SQL2008R2\"
:setvar DefaultLogPath "F:\SQL2008R2\"

GO
:on error exit
GO
/*
Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported.
To re-enable the script after enabling SQLCMD mode, execute the following:
SET NOEXEC OFF; 
*/
:setvar __IsSqlCmdEnabled "True"
GO
IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
    BEGIN
        PRINT N'SQLCMD mode must be enabled to successfully execute this script.';
        SET NOEXEC ON;
    END


GO
USE [$(DatabaseName)];


GO
PRINT N'Creating [voc]...';


GO
CREATE SCHEMA [voc]
    AUTHORIZATION [dbo];


GO
PRINT N'Creating [dbo].[Lingue]...';


GO
CREATE TABLE [dbo].[Lingue] (
    [Lingua]            NVARCHAR (3)  NOT NULL,
    [DescrizioneLingua] NVARCHAR (50) NOT NULL,
    CONSTRAINT [PK_Lingue] PRIMARY KEY CLUSTERED ([Lingua] ASC)
);


GO
PRINT N'Creating [dbo].[Vocabolario]...';


GO
CREATE TABLE [dbo].[Vocabolario] (
    [Lingua]     NVARCHAR (3)   NOT NULL,
    [Lemma]      NVARCHAR (50)  NOT NULL,
    [Traduzione] NVARCHAR (500) NOT NULL,
    CONSTRAINT [PK_Vocabolario] PRIMARY KEY CLUSTERED ([Lingua] ASC, [Lemma] ASC)
);


GO
PRINT N'Creating [dbo].[Vocabolario].[I_lemma]...';


GO
CREATE NONCLUSTERED INDEX [I_lemma]
    ON [dbo].[Vocabolario]([Lemma] ASC);


GO
PRINT N'Creating FK_Vocabolario_Lingue...';


GO
ALTER TABLE [dbo].[Vocabolario] WITH NOCHECK
    ADD CONSTRAINT [FK_Vocabolario_Lingue] FOREIGN KEY ([Lingua]) REFERENCES [dbo].[Lingue] ([Lingua]) ON UPDATE CASCADE;


GO
PRINT N'Checking existing data against newly created constraints';


GO
USE [$(DatabaseName)];


GO
ALTER TABLE [dbo].[Vocabolario] WITH CHECK CHECK CONSTRAINT [FK_Vocabolario_Lingue];


GO
PRINT N'Update complete.'
GO
