IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[CancelPolicyProfile]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[CancelPolicyProfile]
  (
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [varchar](50) NOT NULL,
    [Description] [varchar](max) NULL,
    [IsDefault] [bit] NULL,
    CONSTRAINT [PK_CancelPolicyProfile_1] PRIMARY KEY CLUSTERED 
    (
      [Id] ASC
    )
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[CancelPolicyProfileItem]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[CancelPolicyProfileItem]
  (
    [id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [varchar](50) NOT NULL,
    [ReservationType] [int] NOT NULL,
    [CancelTime] [datetime] NULL,
    [CancelDay] [int] NULL,
    [Percentage] [int] NULL,
    CONSTRAINT [PK_CancelPolicyProfile] PRIMARY KEY CLUSTERED 
    (
      [id] ASC
    )
  ) ON [PRIMARY]
END

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[CancelPolicyItemProfileXtab]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[CancelPolicyItemProfileXtab]
  (
    [FK_CancelPolicyItemId] [int] NOT NULL,
    [FK_CancelPolicyProfileId] [int] NOT NULL,
    CONSTRAINT [PK_CancelPolicyItemProfileXtab] PRIMARY KEY CLUSTERED 
    (
      [FK_CancelPolicyItemId] ASC,
      [FK_CancelPolicyProfileId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[CancelPolicyItemProfileXtab]  WITH CHECK ADD  CONSTRAINT [FK_CancelPolicyItemProfileXtab_CancelPolicyProfile] FOREIGN KEY([FK_CancelPolicyProfileId])
  REFERENCES [dbo].[CancelPolicyProfile] ([Id])

  ALTER TABLE [dbo].[CancelPolicyItemProfileXtab] CHECK CONSTRAINT [FK_CancelPolicyItemProfileXtab_CancelPolicyProfile]

  ALTER TABLE [dbo].[CancelPolicyItemProfileXtab]  WITH CHECK ADD  CONSTRAINT [FK_CancelPolicyItemProfileXtab_CancelPolicyProfileItem] FOREIGN KEY([FK_CancelPolicyItemId])
  REFERENCES [dbo].[CancelPolicyProfileItem] ([id])

  ALTER TABLE [dbo].[CancelPolicyItemProfileXtab] CHECK CONSTRAINT [FK_CancelPolicyItemProfileXtab_CancelPolicyProfileItem]
END

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[ProductCancelPolicyProfileXTab]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[ProductCancelPolicyProfileXTab]
  (
    [FK_ProductNumber] [int] NOT NULL,
    [FK_CancelPolicyProfileId] [int] NOT NULL,
    [DateStamp] [datetime] NOT NULL,
    CONSTRAINT [PK_ProductCancelPolicyProfileXTab] PRIMARY KEY CLUSTERED 
    (
      [FK_ProductNumber] ASC,
      [FK_CancelPolicyProfileId] ASC,
      [DateStamp] ASC
    )
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[ProductCancelPolicyProfileXTab]  WITH CHECK ADD  CONSTRAINT [FK_ProductCancelPolicyProfileXTab_CancelPolicyProfile] FOREIGN KEY([FK_CancelPolicyProfileId])
  REFERENCES [dbo].[CancelPolicyProfile] ([Id])

  ALTER TABLE [dbo].[ProductCancelPolicyProfileXTab] CHECK CONSTRAINT [FK_ProductCancelPolicyProfileXTab_CancelPolicyProfile]

  ALTER TABLE [dbo].[ProductCancelPolicyProfileXTab]  WITH CHECK ADD  CONSTRAINT [FK_ProductCancelPolicyProfileXTab_Products] FOREIGN KEY([FK_ProductNumber])
  REFERENCES [dbo].[Products] ([ProductNumber])

  ALTER TABLE [dbo].[ProductCancelPolicyProfileXTab] CHECK CONSTRAINT [FK_ProductCancelPolicyProfileXTab_Products]
END