Insert cities into database

Asked

Viewed 2,185 times

4

Hello, I am creating a database, and in it I will have information of Brazilian municipalities, I imagine that I am certainly not the first to need this information, however I do not know if there is any way to do it automatically, somewhere I can download this database, or some SQL script that enters the information in the database, because doing it manually is not the most advisable.

I’m using postgresql 9.3, I haven’t created the tables for cities yet.

  • The IBGE website provides all cities through some file types. Take a look at this link, which already has the sqls for postgre http://www.ferreiramauricio.com/sql-das-5565-citysbrasiles-seconds-data

  • I have an sql that I use, however is for the MySql, but I believe that with few changes you can achieve your goal. The file is available in: https://github.com/RichardSDias/SQL

  • All States and Municipalities (or almost all...) of Brazil, with the possibility of inserting new countries, districts/states and municipalities. (Columns with prefix to facilitate Joins and maintain organization...). If you have a problem with accented characters, open the file in any text editor and save it with UTF-8 encoding, which resolves, or copy and paste the code directly into Mysql (without using import...) I’ll leave the project link Github: https://github.com/chinnonsantos/sql-paises-estados-cidades

  • You can use the open source project I created, it searches directly in the ibge API and assembles the most updated list possible according to this data, follows the link http://ibge-sql.herokuapp.com

1 answer

6


IBGE registration code

https://ferreiramauricio.s3.amazonaws.com/files/resource/24/brasil.mysql.sql

Copy everything from the

CREATE TABLE cidades (
    id integer NOT NULL AUTO_INCREMENT,
    nome varchar(250),
    codigo_ibge integer,
    estado_id integer,
    populacao_2010 integer,
    densidade_demo numeric(10, 2),
    gentilico varchar(250),
    area numeric(10, 3),
    PRIMARY KEY (`id`)
);

and performs on your Postgre

also copy the above mentioned CREATE TABLE

  • In the link has mysql, it will work the same way? do not know the differences between one and the other

  • @Lucasmotta Yes, mysql and sql most commands are equal

Browser other questions tagged

You are not signed in. Login or sign up in order to post.