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

	CREATE TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA](
		[CD_EMP] [int] NOT NULL,
		[CD_FILIAL] [int] NOT NULL,
		[CD_CTR] [int] NOT NULL,
		[CD_PED] [int] NOT NULL,
	 CONSTRAINT [PK_EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA] PRIMARY KEY CLUSTERED 
	(
		[CD_EMP] ASC,
		[CD_FILIAL] ASC,
		[CD_CTR] ASC,
		[CD_PED] 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_EST_PED_VD_DEVOLVIDA]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA_EST_PED_VD] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_PED])
	REFERENCES [dbo].[EST_PED_VD] ([CD_EMP], [CD_FILIAL], [CD_PED])

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA] CHECK CONSTRAINT [FK_EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA_EST_PED_VD]

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA_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_EST_PED_VD_DEVOLVIDA] CHECK CONSTRAINT [FK_EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA_EST_PROD_TRILHO_EXCESSO]

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA] ADD  CONSTRAINT [DF_EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA] ADD  CONSTRAINT [DF_EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA] ADD  CONSTRAINT [DF_EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA_CD_CTR]  DEFAULT ((0)) FOR [CD_CTR]

	ALTER TABLE [dbo].[EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA] ADD  CONSTRAINT [DF_EST_PROD_TRILHO_EXCESSO_EST_PED_VD_DEVOLVIDA_CD_PED]  DEFAULT ((0)) FOR [CD_PED]
END