IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE 
	TABLE_NAME = 'publ_PurchaseOrderDocumentTypeDocumentStatus')
BEGIN
	SET ANSI_NULLS ON

	SET QUOTED_IDENTIFIER ON

	CREATE TABLE [dbo].[publ_PurchaseOrderDocumentTypeDocumentStatus](
		[DocumentTypeId] [int] NOT NULL,
		[DocumentStatusId] [int] NOT NULL,
	 CONSTRAINT [PK_publ_PurchaseOrderDocumentTypeDocumentStatus] PRIMARY KEY CLUSTERED 
	(
		[DocumentTypeId] ASC,
		[DocumentStatusId] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY]

	ALTER TABLE [dbo].[publ_PurchaseOrderDocumentTypeDocumentStatus]  WITH CHECK ADD  CONSTRAINT [FK_publ_PurchaseOrderDocumentTypeDocumentStatus_publ_PurchaseOrderDocumentStatuses] FOREIGN KEY([DocumentStatusId])
	REFERENCES [dbo].[publ_PurchaseOrderDocumentStatuses] ([id])

	ALTER TABLE [dbo].[publ_PurchaseOrderDocumentTypeDocumentStatus] CHECK CONSTRAINT [FK_publ_PurchaseOrderDocumentTypeDocumentStatus_publ_PurchaseOrderDocumentStatuses]

	ALTER TABLE [dbo].[publ_PurchaseOrderDocumentTypeDocumentStatus]  WITH CHECK ADD  CONSTRAINT [FK_publ_PurchaseOrderDocumentTypeDocumentStatus_publ_PurchaseOrderDocumentTypes] FOREIGN KEY([DocumentTypeId])
	REFERENCES [dbo].[publ_PurchaseOrderDocumentTypes] ([id])

	ALTER TABLE [dbo].[publ_PurchaseOrderDocumentTypeDocumentStatus] CHECK CONSTRAINT [FK_publ_PurchaseOrderDocumentTypeDocumentStatus_publ_PurchaseOrderDocumentTypes]
END

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE 
	TABLE_NAME = 'publ_PurchaseOrderDocumentTypeStatus')
BEGIN
	SET ANSI_NULLS ON

	SET QUOTED_IDENTIFIER ON

	CREATE TABLE [dbo].[publ_PurchaseOrderDocumentTypeStatus](
		[DocumentTypeId] [int] NOT NULL,
		[PurchaseOrderStatusId] [int] NOT NULL,
	 CONSTRAINT [PK_publ_PurchaseOrderDocumentTypeStatus] PRIMARY KEY CLUSTERED 
	(
		[DocumentTypeId] ASC,
		[PurchaseOrderStatusId] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY]

	ALTER TABLE [dbo].[publ_PurchaseOrderDocumentTypeStatus]  WITH CHECK ADD  CONSTRAINT [FK_publ_PurchaseOrderDocumentTypeStatus_publ_PurchaseOrderDocumentTypes] FOREIGN KEY([DocumentTypeId])
	REFERENCES [dbo].[publ_PurchaseOrderDocumentTypes] ([id])

	ALTER TABLE [dbo].[publ_PurchaseOrderDocumentTypeStatus] CHECK CONSTRAINT [FK_publ_PurchaseOrderDocumentTypeStatus_publ_PurchaseOrderDocumentTypes]

	ALTER TABLE [dbo].[publ_PurchaseOrderDocumentTypeStatus]  WITH CHECK ADD  CONSTRAINT [FK_publ_PurchaseOrderDocumentTypeStatus_publ_PurchaseOrderStatuses] FOREIGN KEY([PurchaseOrderStatusId])
	REFERENCES [dbo].[publ_PurchaseOrderStatuses] ([id])

	ALTER TABLE [dbo].[publ_PurchaseOrderDocumentTypeStatus] CHECK CONSTRAINT [FK_publ_PurchaseOrderDocumentTypeStatus_publ_PurchaseOrderStatuses]
END


