IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[RateLevelRoomTypeRestrictionMulti]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[RateLevelRoomTypeRestrictionMulti]
  (
    [FKRateLevelRoomTypeXTabId] [int] NOT NULL,
    [DateStamp] [datetime] NOT NULL,
    [StopSell] [bit] NULL,
    [SoftClose] [bit] NULL,
    [CTA] [bit] NULL,
    [CTD] [bit] NULL,
    [MLOS] [int] NULL,
    [MaxLOS] [int] NULL,
    [ExactLOS] [int] NULL,
    [ReleaseDays] [int] NULL,
    [CutOffDays] [int] NULL,
    [ReleaseTime] [datetime] NULL,
    CONSTRAINT [PK_RateLevelRoomTypeRestrictionMulti] PRIMARY KEY CLUSTERED 
    (
      [FKRateLevelRoomTypeXTabId] ASC,
      [DateStamp] ASC
    )
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[RateLevelRoomTypeRestrictionMulti]  WITH CHECK ADD  CONSTRAINT [FK_RateLevelRoomTypeRestrictionMulti_RateLevelRoomTypeXTab] FOREIGN KEY([FKRateLevelRoomTypeXTabId])
  REFERENCES [dbo].[RateLevelRoomTypeXTab] ([Id])

  ALTER TABLE [dbo].[RateLevelRoomTypeRestrictionMulti] CHECK CONSTRAINT [FK_RateLevelRoomTypeRestrictionMulti_RateLevelRoomTypeXTab]
END

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[OTAAvailNotifLogMulti]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[OTAAvailNotifLogMulti]
  (
    [DateStamp] [datetime] NOT NULL,
    [FKRateLevelChannelId] [int] NOT NULL,
    [FKProductNumber] [int] NOT NULL,
    [FKRoomTypeNumber] [int] NOT NULL,
    [StopSell] [bit] NULL,
    [SoftClose] [bit] NULL,
    [CTA] [bit] NULL,
    [CTD] [bit] NULL,
    [MLOS] [int] NULL,
    [MaxLOS] [int] NULL,
    [ExactLOS] [int] NULL,
    [ReleaseDays] [int] NULL,
    [CutOffDays] [int] NULL,
    [ReleaseTime] [datetime] NULL,
    CONSTRAINT [PK_OTAAvailNotifLogMulti] PRIMARY KEY CLUSTERED 
    (
      [DateStamp] ASC,
      [FKRateLevelChannelId] ASC,
      [FKProductNumber] ASC,
      [FKRoomTypeNumber] ASC
    )
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[OTAAvailNotifLogMulti]  WITH CHECK ADD  CONSTRAINT [FK_OTAAvailNotifLogMulti_Products] FOREIGN KEY([FKProductNumber])
  REFERENCES [dbo].[Products] ([ProductNumber])

  ALTER TABLE [dbo].[OTAAvailNotifLogMulti] CHECK CONSTRAINT [FK_OTAAvailNotifLogMulti_Products]

  ALTER TABLE [dbo].[OTAAvailNotifLogMulti]  WITH CHECK ADD  CONSTRAINT [FK_OTAAvailNotifLogMulti_RateLevelChannel] FOREIGN KEY([FKRateLevelChannelId])
  REFERENCES [dbo].[RateLevelChannel] ([RateLevelChannelId])

  ALTER TABLE [dbo].[OTAAvailNotifLogMulti] CHECK CONSTRAINT [FK_OTAAvailNotifLogMulti_RateLevelChannel]

  ALTER TABLE [dbo].[OTAAvailNotifLogMulti]  WITH CHECK ADD  CONSTRAINT [FK_OTAAvailNotifLogMulti_RoomTypes] FOREIGN KEY([FKRoomTypeNumber])
  REFERENCES [dbo].[RoomTypes] ([RoomTypeNumber])

  ALTER TABLE [dbo].[OTAAvailNotifLogMulti] CHECK CONSTRAINT [FK_OTAAvailNotifLogMulti_RoomTypes]
END

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ReleaseTime'
    WHERE SysObjects.Name = 'RateLevelRoomTypeRestrictionMulti'
)
  ALTER TABLE RateLevelRoomTypeRestrictionMulti ADD ReleaseTime DATETIME NULL 
GO

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'ReleaseTime'
    WHERE SysObjects.Name = 'OTAAvailNotifLogMulti'
)
  ALTER TABLE OTAAvailNotifLogMulti ADD ReleaseTime DATETIME NULL 
GO