/****** Object:  Table [dbo].[EST_PROD_CPL_ACERTO_CUSTO]    Script Date: 07/23/2013 12:33:29 ******/
IF  NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO]') AND type in (N'U'))
begin
	CREATE TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO](
		[CD_EMP] [int] NOT NULL,
		[CD_FIL_ORIG] [int] NOT NULL, 
		[CD_NF_SAI] [int] NOT NULL,
		[CD_FIL_DEST] [int] NOT NULL,
		[CD_NF_ENT] [int] NOT NULL, 
		[CD_PROD] [int] NOT NULL,
		[VLR_CUSTO_ACERTO] [money] NOT NULL,
		[DT_EMI_NF] [datetime] NOT NULL,
		[DT_ENT_NF] [datetime] NOT NULL,
		[TP_AJUSTE] [int] NOT NULL,
		[CD_USU] [int] NOT NULL,
		[DT_CAD] [datetime] NOT NULL,  
	CONSTRAINT [PK_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] PRIMARY KEY CLUSTERED 
		(
			[CD_EMP] ,
			[CD_FIL_ORIG]  , 
			[CD_NF_SAI]  ,
			[CD_FIL_DEST]  ,
			[CD_NF_ENT]  , 
			[CD_PROD]   
		)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_EST_NF_SAI_TRANSF_ACERTO_CUSTO]  
		WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_EST_NF_ENT_EST_NF_SAI_TRANSF]
			 FOREIGN KEY(CD_EMP, CD_FIL_ORIG, CD_FIL_DEST, CD_NF_SAI, CD_NF_ENT)
	REFERENCES 
		[DBO].[EST_NF_ENT_EST_NF_SAI_TRANSF] (CD_EMP, CD_FIL_ORIG, CD_FIL_DEST, CD_NF_SAI, CD_NF_ENT) ON DELETE CASCADE
		
	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] 
		CHECK CONSTRAINT [FK_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_EST_NF_ENT_EST_NF_SAI_TRANSF] 
	  
	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_CD_FIL_ORIG]  DEFAULT ((0)) FOR [CD_FIL_ORIG]

	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_CD_NF_SAI]  DEFAULT ((0)) FOR [CD_NF_SAI] 
	
	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_CD_FIL_DEST]  DEFAULT ((0)) FOR [CD_FIL_DEST]

	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_CD_NF_ENT]  DEFAULT ((0)) FOR [CD_NF_ENT]
	
	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_CD_PROD]  DEFAULT ((0)) FOR [CD_PROD]

	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_VLR_CUSTO_ACERTO]  DEFAULT ((0)) FOR [VLR_CUSTO_ACERTO]

	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_CD_USU]  DEFAULT ((0)) FOR [CD_USU]
	
	ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_EST_NF_SAI_TRANSF_ACERTO_CUSTO_TP_AJUSTE]  DEFAULT ((0)) FOR [TP_AJUSTE]
end