IF EXISTS (SELECT 1 FROM SYS.COLUMNS WHERE NAME ='CD_CTR' AND OBJECT_ID=OBJECT_ID('PDV_VD_EST_PED_VD_AGRUPAMENTO'))
BEGIN

	UPDATE [PDV_VD_EST_PED_VD_AGRUPAMENTO]
	SET CD_CTR = 0
	WHERE CD_CTR IS NULL
 
	ALTER TABLE [PDV_VD_EST_PED_VD_AGRUPAMENTO]
	ALTER COLUMN CD_CTR INT NOT NULL
 
	ALTER TABLE [PDV_VD_EST_PED_VD_AGRUPAMENTO]
	ADD CONSTRAINT DF_PDV_VD_EST_PED_VD_AGRUPAMENTO_CD_CTR DEFAULT 0 FOR CD_CTR;
 
	ALTER TABLE [dbo].[PDV_VD_EST_PED_VD_AGRUPAMENTO] DROP CONSTRAINT [PK_PDV_VD_EST_PED_VD_AGRUPAMENTO]

	ALTER TABLE [dbo].[PDV_VD_EST_PED_VD_AGRUPAMENTO] ADD CONSTRAINT [PK_PDV_VD_EST_PED_VD_AGRUPAMENTO] PRIMARY KEY CLUSTERED 
	(
		[CD_EMP] ASC,
		[CD_FILIAL] ASC,
		[CD_PED] ASC,
		[CD_FILIAL_VD] ASC,
		[CD_VD] ASC,
		[CD_FILIAL_PED] ASC,
		[CD_CTR] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

END

