IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.RateLevelRoomTypeXTab_Hist') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE dbo.RateLevelRoomTypeXTab_Hist
  (
    [Id] [int] NOT NULL,
    [FKRateLevelId] [int] NOT NULL,
    [FKRoomTypeNumber] [int] NULL,
    [UpdDateTime] [DATETIME] NULL,
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[RateLevelRoomTypeXTab_Hist]  WITH NOCHECK ADD  CONSTRAINT [FK_RateLevelRoomTypeXTab_Hist_RateLevel] FOREIGN KEY([FKRateLevelId])
  REFERENCES [dbo].[RateLevel] ([RateLevelId])

  ALTER TABLE [dbo].[RateLevelRoomTypeXTab_Hist] NOCHECK CONSTRAINT [FK_RateLevelRoomTypeXTab_Hist_RateLevel]

  ALTER TABLE [dbo].[RateLevelRoomTypeXTab_Hist]  WITH NOCHECK ADD  CONSTRAINT [FK_RateLevelRoomTypeXTab_Hist_ROOMTYPES] FOREIGN KEY([FKRoomTypeNumber])
  REFERENCES [dbo].[ROOMTYPES] ([RoomTypeNumber])

  ALTER TABLE [dbo].[RateLevelRoomTypeXTab_Hist] NOCHECK CONSTRAINT [FK_RateLevelRoomTypeXTab_Hist_ROOMTYPES]
END
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.RateLevelRoomTypeRestrictionXTab_Hist') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[RateLevelRoomTypeRestrictionXTab_Hist]
  (
    [FKRateLevelRoomTypeXTabId] [int] NOT NULL,
    [FKRateLevelRestrictionId] [int] NOT NULL,
    [DateStamp] [datetime] NOT NULL,
    [RestrictionLength] [int] NULL,
    [RoomsAllocated] [int] NULL,
    [RoomsAvailableRoomType] [int] NULL,
    [RoomsAvailableTotal] [int] NULL,
    [UpdDateTime] [DATETIME] NULL,
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[RateLevelRoomTypeRestrictionXTab_Hist]  WITH NOCHECK ADD  CONSTRAINT [FK_RateLevelRoomTypeRestrictionXTab_Hist_RateLevelRestriction] FOREIGN KEY([FKRateLevelRestrictionId])
  REFERENCES [dbo].[RateLevelRestriction] ([Id])

  ALTER TABLE [dbo].[RateLevelRoomTypeRestrictionXTab_Hist] NOCHECK CONSTRAINT [FK_RateLevelRoomTypeRestrictionXTab_Hist_RateLevelRestriction]
END
GO

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