ALTER TABLE dbo.PDV_VD_EST_PED_VD_AGRUPAMENTO
	DROP CONSTRAINT FK_PDV_VD_EST_PED_VD_AGRUPAMENTO_EST_PED_VD
GO
GO
GO
ALTER TABLE dbo.PDV_VD_EST_PED_VD_AGRUPAMENTO ADD
	CD_FILIAL_PED int NOT NULL CONSTRAINT DF_PDV_VD_EST_PED_VD_AGRUPAMENTO_CD_FILIAL_PED DEFAULT 0
GO
update
	PDV_VD_EST_PED_VD_AGRUPAMENTO
set 
	CD_FILIAL_PED = CD_FILIAL 
go
ALTER TABLE dbo.PDV_VD_EST_PED_VD_AGRUPAMENTO
	DROP CONSTRAINT PK_PDV_VD_EST_PED_VD_AGRUPAMENTO
GO
ALTER TABLE dbo.PDV_VD_EST_PED_VD_AGRUPAMENTO ADD CONSTRAINT
	PK_PDV_VD_EST_PED_VD_AGRUPAMENTO PRIMARY KEY CLUSTERED 
	(
	CD_EMP,
	CD_FILIAL,
	CD_PED,
	CD_FILIAL_VD,
	CD_VD,
	CD_FILIAL_PED
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
ALTER TABLE dbo.PDV_VD_EST_PED_VD_AGRUPAMENTO ADD CONSTRAINT
	FK_PDV_VD_EST_PED_VD_AGRUPAMENTO_EST_PED_VD FOREIGN KEY
	(
	CD_EMP,
	CD_FILIAL_PED,
	CD_PED
	) REFERENCES dbo.EST_PED_VD
	(
	CD_EMP,
	CD_FILIAL,
	CD_PED
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 