-- SE CD_CTR JÁ FOR BIGNIT E ESTIVER NA PK
IF EXISTS (SELECT *
			  FROM INFORMATION_SCHEMA.COLUMNS COL
			  JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS CON ON CON.TABLE_NAME = COL.TABLE_NAME 
			  WHERE COL.TABLE_NAME = 'PDV_VD_IT_FISCAL_ALTERACAO' 
			   AND COL.COLUMN_NAME = 'CD_CTR' 
			   AND COL.DATA_TYPE = 'BIGINT'
			   AND CON.CONSTRAINT_NAME='PK_PDV_VD_IT_FISCAL_ALTERACAO')
		 
		-- SE IDENTIFICAR QUE O TIPO CD_CTR É INTEIRO E CONSTRAINT EXISTIR 
		IF EXISTS (SELECT *
						FROM INFORMATION_SCHEMA.COLUMNS COL
						JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS CON ON CON.TABLE_NAME = COL.TABLE_NAME 
						WHERE COL.TABLE_NAME = 'PDV_VD_IT_FISCAL_ALTERACAO' 
						 AND COL.COLUMN_NAME = 'CD_CTR' 
						 AND COL.DATA_TYPE = 'INT'
						 AND CON.CONSTRAINT_NAME='PK_PDV_VD_IT_FISCAL_ALTERACAO')
			   BEGIN
					ALTER TABLE PDV_VD_IT_FISCAL_ALTERACAO DROP CONSTRAINT PK_PDV_VD_IT_FISCAL_ALTERACAO;--DELETA A CONSTRAINT
					ALTER TABLE PDV_VD_IT_FISCAL_ALTERACAO ALTER COLUMN CD_CTR BIGINT ;	  --ALTERA O TIPO DA COLUNA CD_CTR 	
					ALTER TABLE PDV_VD_IT_FISCAL_ALTERACAO ADD CONSTRAINT PK_PDV_VD_IT_FISCAL_ALTERACAO PRIMARY KEY (CD_CTR)--CRIA A CONSTRAINT COM O TIPO NOVO PARA CD_CTR
			 
			   END
		ELSE --SE NÃO EXISTIR A CONSTRAINT PARA ESSA TABELA 
		IF NOT EXISTS (SELECT *
						FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS  
						WHERE CONSTRAINT_NAME='PK_PDV_VD_IT_FISCAL_ALTERACAO')	
		BEGIN
			ALTER TABLE PDV_VD_IT_FISCAL_ALTERACAO ALTER COLUMN CD_CTR BIGINT ;	  --ALTERA O TIPO DA COLUNA CD_CTR 	
			ALTER TABLE PDV_VD_IT_FISCAL_ALTERACAO ADD CONSTRAINT PK_PDV_VD_IT_FISCAL_ALTERACAO PRIMARY KEY (CD_CTR)--CRIA A CONSTRAINT COM O TIPO NOVO PARA CD_CTR
	
		END	
