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

CREATE TABLE [dbo].[ConferenceRoomsCategoryGroupXtab](
	[FK_ConferenceRoomNumber] [int] NOT NULL,
	[FK_CategoryGroupNumber] [int] NOT NULL
) ON [PRIMARY]

GO

IF NOT EXISTS (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_ConferenceRoomsCategoryGroupXtab_CategoryGroup')
  ALTER TABLE [dbo].[ConferenceRoomsCategoryGroupXtab]  WITH CHECK ADD  CONSTRAINT [FK_ConferenceRoomsCategoryGroupXtab_CategoryGroup] FOREIGN KEY([FK_CategoryGroupNumber])
  REFERENCES [dbo].[CategoryGroup] ([GroupNumber])
  GO

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

IF NOT EXISTS (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_ConferenceRoomsCategoryGroupXtab_CONFERENCEROOMS')
ALTER TABLE [dbo].[ConferenceRoomsCategoryGroupXtab]  WITH CHECK ADD  CONSTRAINT [FK_ConferenceRoomsCategoryGroupXtab_CONFERENCEROOMS] FOREIGN KEY([FK_ConferenceRoomNumber])
REFERENCES [dbo].[CONFERENCEROOMS] ([ConferenceRoomNumber])
GO

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


