IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD]')) 
	begin
		return;
	end
else
begin
	/****** Object:  Table [dbo].[PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD]    Script Date: 23/06/2014 09:53:45 ******/
	SET ANSI_NULLS ON  
	SET QUOTED_IDENTIFIER ON 

	CREATE TABLE [dbo].[PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD](
		[CD_EMP]			[int] NOT NULL CONSTRAINT [DF_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_CD_EMP]  DEFAULT ((0)),
		[CD_CTR_DEPO]		[int] NOT NULL CONSTRAINT [DF_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_CD_CTR_DEPO]  DEFAULT ((0)),
		[CD_CTR_DEPO_AUX]	[int] NOT NULL CONSTRAINT [DF_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_CD_CTR_DEPO_AUX]  DEFAULT ((0)),
		[CD_FILIAL_DEPO]			[int] NOT NULL CONSTRAINT [DF_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_CD_FILIAL_DEPO]  DEFAULT ((0)),
		[CD_FILIAL_DEPO_AUX]		[int] NOT NULL CONSTRAINT [DF_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_CD_FILIAL_DEPO_AUX]  DEFAULT ((0)),
		[CD_PROD]		[int] NOT NULL CONSTRAINT [DF_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_CD_PROD]  DEFAULT ((0)), 
		[CD_USU]		[int] NOT NULL CONSTRAINT [DF_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_CD_USU]  DEFAULT ((0)), 
		[DT_CAD]		[datetime] ,
	 CONSTRAINT [PK_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD] PRIMARY KEY CLUSTERED 
	(
		[CD_PROD]	  ASC,
		[CD_EMP]	  ASC,
		[CD_CTR_DEPO] ASC,
		[CD_CTR_DEPO_AUX] 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].[PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD]  WITH NOCHECK 
		ADD  CONSTRAINT [FK_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_PRC_FILIAL_DEPOSITO] 
		FOREIGN KEY([CD_CTR_DEPO])
		REFERENCES [dbo].[PRC_FILIAL_DEPOSITO] ([CD_CTR_DEPO]) 
	ALTER TABLE [dbo].[PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD] 
		CHECK CONSTRAINT [FK_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_PRC_FILIAL_DEPOSITO]
	
	ALTER TABLE [dbo].[PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD]  WITH NOCHECK 
		ADD  CONSTRAINT [FK_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_PRC_FILIAL_DEPOSITO_AUXILIAR] 
		FOREIGN KEY([CD_EMP],[CD_CTR_DEPO],[CD_CTR_DEPO_AUX]) 
		REFERENCES [dbo].[PRC_FILIAL_DEPOSITO_AUXILIAR] ([CD_EMP],[CD_CTR_DEPO],[CD_CTR_DEPO_AUX]) 
	ALTER TABLE [dbo].[PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD] 
		CHECK CONSTRAINT [FK_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_PRC_FILIAL_DEPOSITO_AUXILIAR] 
	
	ALTER TABLE [dbo].[PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD]  WITH NOCHECK 
		ADD  CONSTRAINT [FK_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_EST_PROD] 
		FOREIGN KEY([CD_EMP],[CD_PROD]) 
		REFERENCES [dbo].[EST_PROD] ([CD_EMP], [CD_PROD]) 
	ALTER TABLE [dbo].[PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD] 
		CHECK CONSTRAINT [FK_PRC_FILIAL_DEPOSITO_AUXILIAR_EST_PROD_EST_PROD]
END
