IF OBJECT_ID('EST_PED_CP_IT_COMPRADOR') IS NULL
BEGIN
CREATE TABLE [dbo].[EST_PED_CP_IT_COMPRADOR](
	[CD_EMP] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[CD_PED] [int] NOT NULL,
	[CD_PROD] [int] NOT NULL,
	[CD_COMPRADOR] [int] NOT NULL,
	[DT_CAD] [datetime] NULL,
 CONSTRAINT [PK_EST_PED_CP_IT_COMPRADOR] PRIMARY KEY CLUSTERED 
(
	[CD_EMP] ASC,
	[CD_FILIAL] ASC,
	[CD_PED] ASC,
	[CD_COMPRADOR] ASC,
	[CD_PROD] 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].[EST_PED_CP_IT_COMPRADOR]  WITH CHECK ADD  CONSTRAINT [FK_EST_PED_CP_IT_COMPRADOR_EST_PED_CP_IT] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_PED], [CD_PROD])
REFERENCES [dbo].[EST_PED_CP_IT] ([CD_EMP], [CD_FILIAL], [CD_PED], [CD_PROD])
ON UPDATE CASCADE
ON DELETE CASCADE

ALTER TABLE [dbo].[EST_PED_CP_IT_COMPRADOR] CHECK CONSTRAINT [FK_EST_PED_CP_IT_COMPRADOR_EST_PED_CP_IT]
END

