IF  NOT EXISTS (SELECT * FROM sys.objects 
					WHERE object_id = OBJECT_ID(N'[dbo].[EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP]') 
					AND type in (N'U')) 
BEGIN

	/****** Object:  Table [dbo].[EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP]    Script Date: 21/05/2015 11:10:41 ******/
	SET ANSI_NULLS ON 
	SET QUOTED_IDENTIFIER ON 

	CREATE TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP](
		[CD_CTR] [int] NOT NULL,
		[CD_EMP] [int] NOT NULL,
		[CD_FILIAL] [int] NOT NULL,
		[CD_PED] [int] NOT NULL, 
		[CD_USU] [int] NOT NULL, 
		[DT_CAD] [datetime] NOT NULL, 
	 CONSTRAINT [PK_EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP] PRIMARY KEY CLUSTERED 
	( 
		[CD_CTR] 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_NF_ENT_DANFE_PROVISORIO_EST_PED_CP]  
		WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP_EST_NF_ENT_DANFE_PROVISORIO] FOREIGN KEY([CD_CTR])
	REFERENCES [dbo].[EST_NF_ENT_DANFE_PROVISORIO] ([CD_CTR])
	ON UPDATE CASCADE
	ON DELETE CASCADE 

	ALTER TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP] CHECK CONSTRAINT [FK_EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP_EST_NF_ENT_DANFE_PROVISORIO]
 
	ALTER TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP]  WITH NOCHECK ADD  CONSTRAINT [FK_EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP_EST_PED_CP] 
			FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_PED])
	REFERENCES [dbo].[EST_PED_CP] ([CD_EMP], [CD_FILIAL], [CD_PED])
	ON UPDATE CASCADE
	ON DELETE CASCADE 

	ALTER TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP] CHECK CONSTRAINT [FK_EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP_EST_PED_CP]
	
	CREATE UNIQUE NONCLUSTERED INDEX IDX_UK_EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP
		ON [dbo].[EST_NF_ENT_DANFE_PROVISORIO_EST_PED_CP] ([CD_CTR],[CD_PED],[CD_FILIAL],[CD_EMP]) 

END
