IF OBJECT_ID('GLB_UF') IS NULL
	CREATE TABLE GLB_UF(
		UF varchar(2) NOT NULL,
		DS_UF varchar(20) NOT NULL,
		CD_UF int NOT NULL,
	 CONSTRAINT PK_GLB_UF PRIMARY KEY CLUSTERED (UF ASC)
	 WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
	);
GO

IF NOT OBJECT_ID('V_GLB_CID_IPDV') IS NULL
    DROP VIEW V_GLB_CID_IPDV;
GO

	CREATE VIEW V_GLB_CID_IPDV AS
	SELECT GLB_CID.CD_CID, GLB_CID.DS_CID, GLB_CID.UF, GLB_CID.CEP, GLB_CID.CD_PAIS, GLB_CID.CD_IBGE,
	GLB_UF.CD_UF AS CD_UF_IBGE, GLB_MUNICIPIO.COD_MUNICIPIO_SINTEGRA AS CD_MUNICIPIO_IBGE
	FROM         GLB_CID 
	LEFT JOIN GLB_UF
	ON GLB_CID.UF = GLB_UF.UF COLLATE SQL_Latin1_General_CP1_CI_AI
	LEFT JOIN GLB_CID_GLB_MUNICIPIO
	ON GLB_CID_GLB_MUNICIPIO.CD_CID = GLB_CID.CD_CID
	LEFT JOIN GLB_MUNICIPIO
	ON GLB_CID_GLB_MUNICIPIO.CD_MUNICIPIO = GLB_MUNICIPIO.CD_MUNICIPIO;
GO
