IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[RecurringPatternWareCache]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
  CREATE TABLE [dbo].[RecurringPatternWareCache]
  (
    [WareNumber] [int] NOT NULL,
    [StartDateTime] [datetime] NOT NULL,
    [EndDateTime] [datetime] NOT NULL,
    [Available] [int] NOT NULL,
    CONSTRAINT [PK_RecurringPatternGetWare] PRIMARY KEY CLUSTERED 
    (
      [WareNumber] ASC,
      [StartDateTime] ASC,
      [EndDateTime] ASC
    )
  ) ON [PRIMARY]

  ALTER TABLE [dbo].[RecurringPatternWareCache]  WITH NOCHECK ADD  CONSTRAINT [FK_RecurringPatternGetWare_Ware] FOREIGN KEY([WareNumber])
  REFERENCES [dbo].[Ware] ([WareNumber])

  ALTER TABLE [dbo].[RecurringPatternWareCache] CHECK CONSTRAINT [FK_RecurringPatternGetWare_Ware]
END