IF NOT EXISTS(SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.OTAAvailNotifLog') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[OTAAvailNotifLog]
  (
    [DateStamp] [datetime] NOT NULL,
    [FKRateLevelChannelId] [int] NOT NULL,
    [FKRateLevelId] [int] NOT NULL,
    [FKRoomTypeNumber] [int] NOT NULL,
    [FKProductNumber] [int] NOT NULL,
    [RestrictionType] [smallint] NOT NULL,
    [RestrictionLength] [int] NULL,
    [SubmitDateStamp] [datetime] NOT NULL,
    CONSTRAINT [PK_OTAAvailNotifLog] PRIMARY KEY CLUSTERED 
    (
      [DateStamp] ASC,
      [FKRateLevelChannelId] ASC,
      [FKRateLevelId] ASC,
      [FKRoomTypeNumber] ASC,
      [FKProductNumber] ASC
    )
  ) ON [PRIMARY]

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

  ALTER TABLE [dbo].[OTAAvailNotifLog] CHECK CONSTRAINT [FK_OTAAvailNotifLog_Products]

  ALTER TABLE [dbo].[OTAAvailNotifLog]  WITH CHECK ADD  CONSTRAINT [FK_OTAAvailNotifLog_RateLevel] FOREIGN KEY([FKRateLevelId])
  REFERENCES [dbo].[RateLevel] ([RateLevelId])

  ALTER TABLE [dbo].[OTAAvailNotifLog] CHECK CONSTRAINT [FK_OTAAvailNotifLog_RateLevel]

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

  ALTER TABLE [dbo].[OTAAvailNotifLog] CHECK CONSTRAINT [FK_OTAAvailNotifLog_RateLevelChannel]

  ALTER TABLE [dbo].[OTAAvailNotifLog]  WITH NOCHECK ADD  CONSTRAINT [FK_OTAAvailNotifLog_RoomTypes] FOREIGN KEY([FKRoomTypeNumber])
  REFERENCES [dbo].[RoomTypes] ([RoomTypeNumber])

  ALTER TABLE [dbo].[OTAAvailNotifLog] CHECK CONSTRAINT [FK_OTAAvailNotifLog_RoomTypes]
END
ELSE
BEGIN
  IF EXISTS (SELECT * FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = 'FK_OTAAvailNotifLog_RoomTypes')
    ALTER TABLE [dbo].[OTAAvailNotifLog]  NOCHECK CONSTRAINT [FK_OTAAvailNotifLog_RoomTypes] 
END