if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProductsCategoryXtab]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

CREATE TABLE [dbo].[ProductsCategoryXtab](
	[FK_ProductNumber] [int] NOT NULL,
	[FK_CategoryNumber] [int] NOT NULL,
        [CategoryType] [int] NOT NULL
) ON [PRIMARY]

GO

IF NOT EXISTS (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_ProductsCategoryXtab_Category')
  ALTER TABLE [dbo].[ProductsCategoryXtab]  WITH CHECK ADD  CONSTRAINT [FK_ProductsCategoryXtab_Category] FOREIGN KEY([FK_CategoryNumber])
  REFERENCES [dbo].[Category] ([CategoryNumber])
GO

IF EXISTS (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_ProductsCategoryXtab_Category')
  ALTER TABLE [dbo].[ProductsCategoryXtab] CHECK CONSTRAINT [FK_ProductsCategoryXtab_Category]
GO

IF NOT EXISTS (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_ProductsCategoryXtab_Products')
  ALTER TABLE [dbo].[ProductsCategoryXtab]  WITH CHECK ADD  CONSTRAINT [FK_ProductsCategoryXtab_Products] FOREIGN KEY([FK_ProductNumber])
  REFERENCES [dbo].[Products] ([ProductNumber])
GO

IF EXISTS (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_ProductsCategoryXtab_Products')
  ALTER TABLE [dbo].[ProductsCategoryXtab] CHECK CONSTRAINT [FK_ProductsCategoryXtab_Products]
GO


