IF NOT EXISTS (SELECT * FROM SYS.TABLES WHERE NAME = 'EST_PROD_TRILHO_EXCESSO_PRC_FILIAL') 
BEGIN

	CREATE TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_PRC_FILIAL](
		[CD_EMP] [int] NOT NULL,
		[CD_FILIAL] [int] NOT NULL,
		[CD_CTR] [int] NOT NULL,
		[CD_FILIAL_DESTINO] [int] NOT NULL,
	 CONSTRAINT [PK_EST_PROD_TRILHO_EXCESSO_PRC_FILIAL] PRIMARY KEY CLUSTERED 
	(
		[CD_EMP] ASC,
		[CD_FILIAL] ASC,
		[CD_CTR] ASC
	)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_PRC_FILIAL]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TRILHO_EXCESSO_PRC_FILIAL_EST_PROD_TRILHO_EXCESSO] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_CTR])
	REFERENCES [dbo].[EST_PROD_TRILHO_EXCESSO] ([CD_EMP], [CD_FILIAL], [CD_CTR])

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_PRC_FILIAL] CHECK CONSTRAINT [FK_EST_PROD_TRILHO_EXCESSO_PRC_FILIAL_EST_PROD_TRILHO_EXCESSO]

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_PRC_FILIAL]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TRILHO_EXCESSO_PRC_FILIAL_PRC_FILIAL] FOREIGN KEY([CD_EMP], [CD_FILIAL])
	REFERENCES [dbo].[PRC_FILIAL] ([CD_EMP], [CD_FILIAL])

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_PRC_FILIAL] CHECK CONSTRAINT [FK_EST_PROD_TRILHO_EXCESSO_PRC_FILIAL_PRC_FILIAL]
END