text: ﻿/*
  Deployment script for JQueryContactsChallengeDb
  
  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 "JQueryContactsChallengeDb"
  :setvar DefaultFilePrefix "JQueryContactsChallengeDb"
  :setvar DefaultDataPath ""
  :setvar DefaultLogPath ""
  
  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 [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'Creating $(DatabaseName)...'
  GO
  CREATE DATABASE [$(DatabaseName)] COLLATE SQL_Latin1_General_CP1_CI_AS
  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 FULL,
                  CURSOR_CLOSE_ON_COMMIT OFF,
                  AUTO_CREATE_STATISTICS ON,
                  AUTO_SHRINK OFF,
                  AUTO_UPDATE_STATISTICS ON,
                  RECURSIVE_TRIGGERS OFF 
              WITH ROLLBACK IMMEDIATE;
          ALTER DATABASE [$(DatabaseName)]
              SET AUTO_CLOSE 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'The database settings cannot be modified. You must be a SysAdmin to apply these settings.';
      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'The database settings cannot be modified. You must be a SysAdmin to apply these settings.';
      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
  USE [$(DatabaseName)];
  
  
  GO
  IF fulltextserviceproperty(N'IsFulltextInstalled') = 1
      EXECUTE sp_fulltext_database 'enable';
  
  
  GO
  PRINT N'Creating [dbo].[Contacts]...';
  
  
  GO
  CREATE TABLE [dbo].[Contacts] (
      [Id]    UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
      [Name]  NVARCHAR (255)   NOT NULL,
      [Phone] NVARCHAR (255)   NOT NULL,
      [Email] NVARCHAR (1024)  NOT NULL,
      CONSTRAINT [PK_Contacts] PRIMARY KEY CLUSTERED ([Id] ASC)
  );
  
  
  GO
  PRINT N'Creating [dbo].[DF_Contacts_Id]...';
  
  
  GO
  ALTER TABLE [dbo].[Contacts]
      ADD CONSTRAINT [DF_Contacts_Id] DEFAULT (newid()) FOR [Id];
  
  
  GO
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'066b1443-78fc-49d3-89d8-08a44bc92797', N'Hawkeye', N'407-712-0001', N'pierce@tent1.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'c2ea3e62-7ab6-4c79-b4f0-393d41dcc80d', N'Mary Ann', N'123-456-7896', N'maryann@hut4.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'58bf9a7c-7a3e-4797-bb52-41896c3f33ab', N'Skipper', N'123-456-7891', N'skipper@hut1.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'8c2cf66e-ab50-4cd2-bc02-5775ed654066', N'Mr. Howell', N'123-456-7892', N'thurston@hut2.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'c808652c-67dd-462a-a72d-62303baee2cb', N'Mrs. Howell', N'123-456-7893', N'lovell@hut2.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'2517d9fc-cf28-4f16-9b54-65b9d8c8f3eb', N'Francis', N'407-712-0004', N'Mulcahey@tent4.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'284c5059-cff4-4f49-8ccc-751a9951598b', N'Trapper', N'407-712-0005', N'McIntyre@tent1.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'f28c9c8e-a44e-4f17-9588-7b52593e719c', N'Maxwell', N'407-712-0003', N'klinger@tent3.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'acda7488-67b5-456e-a3da-8574ddd3aacf', N'Frank', N'407-712-0007', N'burns@tent1.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'13f30e6f-962b-4900-878a-90c497c7b97d', N'Radar', N'407-712-0008', N'orielly@tent6.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'5bf5e2ad-31db-4bcb-b2c2-99ea3a252276', N'Henry', N'407-712-0006', N'blake@tent5.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'c7071c7f-de8e-4616-a590-c2ac6eb03258', N'Ginger', N'123-456-7895', N'ginger@hut4.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'1bb83e61-af8a-42a9-b58f-c6722a9ab324', N'Professer', N'123-456-7894', N'roy@hut3.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'3a84b480-c792-4d6e-b0dc-d2386bba200f', N'Margaret', N'407-712-0002', N'houlihan@tent2.com')
  INSERT [dbo].[Contacts] ([Id], [Name], [Phone], [Email]) VALUES (N'11121bdb-b6ea-4a0e-a612-f0c5c61ca2cf', N'Gilligan', N'123-456-7890', N'gilligan@hut1.com')
  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'Update complete.';
  
  
  GO
  