Giter VIP home page Giter VIP logo

vietnamese-provinces-database's Introduction

Repository Banner Made in Vietnam

Đọc phiên bản tiếng Việt

Vietnamese Provinces Database

A complete SQL database of Vietnamese administrative units, includes all 63 Vietnamese provinces and associated districts, wards sub-divisions.
Data is updated as of the most recent effective decree: 1013/NQ-UBTVQH15
Don't forget to leave a ⭐ if you find this repository helpful, and to keep track of the latest release of this dataset in the future. It's would help to cheer us up so we can deliver valuable product to support our community.

Overview

The author(s) of this repository is not associated with the General Statistics Office of Vietnam, nor the Vietnamese government.
The data of provinces, districts and wards are created base on the API province data provided by the General Statistics Office of Vietnam website.
This dataset also include additional information apart from the original provinces, districts and wards data from the original data. Please see section Additional change make by this repository

Dataset releases and Government issued decrees

The Vietnamese Government may issues decree time to time to change the administrative unit structure. You can track the latest issued decrees here.

This dataset will be gradually updated to keep up with the latest effective decree. To check the status of your dataset and how to keep the dataset up-to-date, see section How to update the existing dataset?.

The following tables contains the list of issued decree, its effected date from, tracked from the earliest version of this dataset.

Issued Decree Issued on Effect from Release Version
1013/NQ-UBTVQH15 19/03/2024 01/05/2024 v2.0.1
939/NQ-UBTVQH15 13/12/2023 01/02/2024 v2.0.0
From 721/NQ-UBTVQH15 to
730/NQ-UBTVQH15
13/02/2023 10/04/2023 v1.0.4.1
569/NQ-UBTVQH15,
570/NQ-UBTVQH15
11/08/2022 01/10/2022 v1.0.3.1
510/NQ-UBTVQH15 12/05/2022 01/07/2022 v1.0.2
469/NQ-UBTVQH15 15/02/2022 10/04/2022 v1.0.1
387/NQ-UBTVQH15 22/09/2021 01/11/2021 v1.0.0

Additional change make by this repository

  • Add administrative_regions table
  • Add administrative_units table
  • Define the administrative unit and associated region for province, district and ward data
  • Generate the English name for the provinces, districts and wards, offer both full and short forms
  • Generate the code name for the provinces, districts and wards

Installation

Postgresql

Either use your existing database, or create a new one:

CREATE DATABASE vietnamese_administrative_units;

Execute the CreateTable_vn_units.sql in the postgresql directory first in the target database to generate all the table structure.

Then follow up by executing the ImportData_vn_units.sql to import data to these generated tables.

MySQL - MariaDB

Either use your existing database, or create a new one:

CREATE DATABASE vietnamese_administrative_units;

Execute the CreateTable_vn_units.sql in the mysql directory first in the target database to generate all the table structure.

Then follow up by executing the ImportData_vn_units.sql to import data to these generated tables.

Microsoft SQL Server

Either use your existing database, or create a new one:

CREATE DATABASE vietnamese_administrative_units;

Execute the CreateTable_vn_units.sql in the sqlserver directory first in the target database to generate all the table structure.

Then follow up by executing the ImportData_vn_units.sql to import data to these generated tables.

Oracle

Either use your existing database, or create a new one

Execute the CreateTable_vn_units.sql in the oracle directory first in the target database to generate all the table structure.

Then follow up by executing the ImportData_vn_units.sql to import data to these generated tables.

Tables Schema

VN_administrative_units db

administrative_regions table

VN Geographical Regions
The administrative_regions table contains the list of 8 Vietnamese geographical regions with the id increment following the region location from North to South.

Table definition

Column Data type Meaning Constraint
id integer Id of the region Primary Key
name varchar(255) Region name in Vietnamese
name_en varchar(255) Region name in English
code_name varchar(255) Code name, derived from Vietnamese name, written in lowercase, underscored
code_name_en varchar(255) Code name, derived from English name, written in lowercase, underscored

Data preview

id name name_en code_name code_name_en
1 Đông Bắc Bộ Northeast dong_bac_bo northest
2 Tây Bắc Bộ Northwest tay_bac_bo northwest
3 Đồng bằng sông Hồng Red River Delta dong_bang_song_hong red_river_delta
4 Bắc Trung Bộ North Central Coast bac_trung_bo north_central_coast
5 Duyên hải Nam Trung Bộ South Central Coast duyen_hai_nam_trung_bo south_central_coast
6 Tây Nguyên Central Highlands tay_nguyen central_highlands
7 Đông Nam Bộ Southeast dong_nam_bo southeast
8 Đồng bằng sông Cửu Long Mekong River Delta dong_bang_song_cuu_long southwest

administrative_units table

VN Units

The administrative_units table contains a list of administrative units with id sorted by the tier level from biggest to the smallest unit.

Table definition

Column Data type Meaning Constraint
id integer Id of the administrative unit Primary Key
full_name varchar(255) Full name of the administrative unit in Vietnamese
full_name_en varchar(255) Full name of the administrative unit in English
short_name varchar(255) Short name of the administrative unit in Vietnamese
short_name_en varchar(255) Short name of the administrative unit in English
code_name varchar(255) Code name, derived from Vietnamese full_name, written in lowercase, underscored
code_name_en varchar(255) Code name, derived from English full_name_en, written in lowercase, underscored

Data preview

id full_name full_name_en short_name short_name_en code_name code_name_en
1 Thành phố trực thuộc trung ương Municipality Thành phố City thanh_pho_truc_thuoc_trung_uong municipality
2 Tỉnh Province Tỉnh Province tinh province
3 Thành phố thuộc thành phố trực thuộc trung ương Municipal city Thành phố City thanh_pho_thuoc_thanh_pho_truc_thuoc_trung_uong municipal_city
4 Thành phố thuộc tỉnh Provincial city Thành phố City thanh_pho_thuoc_tinh provincial_city
5 Quận Urban district Quận District quan urban_district
6 Thị xã District-level town Thị xã Town thi_xa district_level_town
7 Huyện District Huyện District huyen district
8 Phường Ward Phường Ward phuong ward
9 Thị trấn Commune-level town Thị trấn Township thi_tran commune_level_town
10 Commune Commune xa commune

provinces table

Provincial level
The provinces table contains a list of first administrative tier - the provincial level units, includes 63 municipalities and provinces.
The code key and full_name are based on the original CSV file.

Table definition

Column Data type Meaning Constraint
code varchar(20) The official unit code, defined by government Primary Key
name varchar(255) Name in Vietnamese
name_en varchar(255) Name of in English
full_name varchar(255) Full name in Vietnamese, includes the administrative unit name
full_name_en varchar(255) Full name in English, includes the administrative unit name
code_name varchar(255) Code name, derived from name, written in lowercase, underscored
administrative_unit_id integer The administrative unit id of this record Foreign Key, references to administrative_units.id
administrative_region_id integer The geographical region this this record belongs to Foreign Key, references to administrative_regions.id

Data preview

code name name_en full_name full_name_en code_name administrative_unit_id administrative_region_id
01 Hà Nội Ha Noi Thành phố Hà Nội Ha Noi City ha_noi 1 3
30 Hải Dương Hai Duong Tỉnh Hải Dương Hai Duong Province hai_duong 2 3
46 Thừa Thiên Huế Thua Thien Hue Tỉnh Thừa Thiên Huế Thua Thien Hue Province thua_thien_hue 2 4
48 Đà Nẵng Da Nang Thành phố Đà Nẵng Da Nang City da_nang 1 5
79 Hồ Chí Minh Ho Chi Minh Thành phố Hồ Chí Minh Ho Chi Minh City ho_chi_minh 1 7
.. ........... ........... ..................... ................ ........... .. ..

districts table

District level The districts table contains a list of second administrative tier - the district level units, includes 705 municipal city, urban districts, district-level towns, districts and provincial cities.
The code key and full_name are based on the original CSV file.

Table definition

Column Data type Meaning Constraint
code varchar(20) The official unit code, defined by government Primary Key
name varchar(255) Name in Vietnamese
name_en varchar(255) Name of in English
full_name varchar(255) Full name in Vietnamese, includes the administrative unit name
full_name_en varchar(255) Full name in English, includes the administrative unit name
code_name varchar(255) Code name, derived from name, written in lowercase, underscored
province_code integer The province this record belongs to Foreign Key, references to provinces.code
administrative_unit_id integer The administrative unit id of this record Foreign Key, references to administrative_units.id

Data preview

code name name_en full_name full_name_en code_name province_code administrative_unit_id
001 Ba Đình Ba Dinh Quận Ba Đình Ba Dinh District ba_dinh 01 5
002 Hoàn Kiếm Hoan Kiem Quận Hoàn Kiếm Hoan Kiem District hoan_kiem 01 5
003 Tây Hồ Tay Ho Quận Tây Hồ Tay Ho District tay_ho 01 5
004 Long Biên Long Bien Quận Long Biên Long Bien District long_bien 01 5
005 Cầu Giấy Cau Giay Quận Cầu Giấy Cau Giay District cau_giay 01 5
... ........ ........ ............. ................. ........ .. ..

wards table

Commune level The wards table contains a list of third administrative tier - the commune level units, includes 10599 wards, communes and commune-level towns.
The code key and full_name are based on the original CSV file.

Table definition

Column Data type Meaning Constraint
code varchar(20) The official unit code, defined by government Primary Key
name varchar(255) Name in Vietnamese
name_en varchar(255) Name of in English
full_name varchar(255) Full name in Vietnamese, includes the administrative unit name
full_name_en varchar(255) Full name in English, includes the administrative unit name
code_name varchar(255) Code name, derived from name, written in lowercase, underscored
district_code integer The district this record belongs to Foreign Key, references to districts.code
administrative_unit_id integer The administrative unit id of this record Foreign Key, references to administrative_units.id

Data preview

code name name_en full_name full_name_en code_name district_code administrative_unit_id
25942 Dĩ An Di An Phường Dĩ An Di An Ward di_an 724 8
25945 Tân Bình Tan Binh Phường Tân Bình Tan Binh Ward tan_binh 724 8
25948 Tân Đông Hiệp Tan Dong Hiep Phường Tân Đông Hiệp Tan Dong Hiep Ward tan_dong_hiep 724 8
25951 Bình An Binh An Phường Bình An Binh An Ward binh_an 724 8
25954 Bình Thắng Binh Thang Phường Bình Thắng Binh Thang Ward binh_thang 724 8
----- ----- ------- --------- ----------- ---------- --- --

Sample Queries

You can easily create query to get all the kind of data you need since the tables are clearly referenced between each others.
Here is some sample queries to start with:

Get all the provinces in a geographical region

Get all provinces in South Central Coast region (id = 5)

SELECT p.code, p."name" , p.full_name , p.full_name_en ,au.full_name as administrative_unit_name
FROM provinces p
INNER JOIN administrative_units au 
ON p.administrative_unit_id = au.id 
WHERE p.administrative_region_id = 5
ORDER BY code;
code name full_name full_name_en administrative_unit_name
48 Đà Nẵng Thành phố Đà Nẵng Da Nang City Thành phố trực thuộc trung ương
49 Quảng Nam Tỉnh Quảng Nam Quang Nam Province Tỉnh
51 Quảng Ngãi Tỉnh Quảng Ngãi Quang Ngai Province Tỉnh
52 Bình Định Tỉnh Bình Định Binh Dinh Province Tỉnh
54 Phú Yên Tỉnh Phú Yên Phu Yen Province Tỉnh
56 Khánh Hòa Tỉnh Khánh Hòa Khanh Hoa Province Tỉnh
58 Ninh Thuận Tỉnh Ninh Thuận Ninh Thuan Province Tỉnh
60 Bình Thuận Tỉnh Bình Thuận Binh Thuan Province Tỉnh

Get all districts under a province

Get all districts under Khánh Hoà province

SELECT d.code, d."name" , d.full_name , d.full_name_en ,au.full_name as administrative_unit_name
FROM districts d 
INNER JOIN administrative_units au 
ON d.administrative_unit_id = au.id
WHERE d.province_code = '56' -- Khanh Hoa province code
ORDER BY d.code;
code name full_name full_name_en administrative_unit_name
568 Nha Trang Thành phố Nha Trang Nha Trang City Thành phố thuộc tỉnh
569 Cam Ranh Thành phố Cam Ranh Cam Ranh City Thành phố thuộc tỉnh
570 Cam Lâm Huyện Cam Lâm Cam Lam District Huyện
571 Vạn Ninh Huyện Vạn Ninh Van Ninh District Huyện
572 Ninh Hòa Thị xã Ninh Hòa Ninh Hoa Town Thị xã
573 Khánh Vĩnh Huyện Khánh Vĩnh Khanh Vinh District Huyện
574 Diên Khánh Huyện Diên Khánh Dien Khanh District Huyện
575 Khánh Sơn Huyện Khánh Sơn Khanh Son District Huyện
576 Trường Sa Huyện Trường Sa Truong Sa District Huyện

Get wards under a district

Get all wards of Ninh Hoa town

SELECT w.code, w."name" , w.full_name , w.full_name_en ,au.full_name as administrative_unit_name
FROM wards w 
INNER JOIN administrative_units au 
ON w.administrative_unit_id = au.id
WHERE w.district_code = '572' -- Ninh Hoa town code
ORDER BY w.code;
code name full_name full_name_en administrative_unit_name
22528 Ninh Hiệp Phường Ninh Hiệp Ninh Hiep Ward Phường
22531 Ninh Sơn Xã Ninh Sơn Ninh Son Commune
22534 Ninh Tây Xã Ninh Tây Ninh Tay Commune
22537 Ninh Thượng Xã Ninh Thượng Ninh Thuong Commune
22540 Ninh An Xã Ninh An Ninh An Commune
22543 Ninh Hải Phường Ninh Hải Ninh Hai Ward Phường
22546 Ninh Thọ Xã Ninh Thọ Ninh Tho Commune
----- -------- ----------- ------ -----
(the rest of rows are removed for brevity)

FAQ

What is the original data source that this repository develope from?

The original data source is the CSV file from the General Statistics Office of Vietnam website.
You can go to the site, tick on the checkbox Quận Huyện, Phường Xã, then click the Xuất Excel button to download the CSV file.

How are the primary keys defined?

Table Primary Key
administrative_regions Key: id. Starting from 1 to 8, follow the geographical location order from North to South
administrative_units Key: id. Starting from 1 to 10, follow the tier order from biggest unit to smallest unit
provinces Key: code. Officially referenced from government unit code
districts Key: code. Officially referenced from government unit code
wards Key: code. Officially referenced from government unit code

I cannot find districts 2, 9 and Thu Duc?

Districts 2, 9 and Thu Duc were merged into a single Thu Duc Municipal city, directly under Ho Chi Minh city recently. Hence all their wards are binded directly under district entity Thu Duc city, code 769.

How to update the existing dataset?

The government may gradually public new decree to change the administrative unit structure overtime.

If you want to check the current up-to-date status of your provinces dataset, simply execute the patch_checker.sql script, and apply the missing decree patch (if any) in the patch directory.

Sample Output from the patch_checker script:

nghidinh_469_nq_ubtvqh15 vietnamese_provinces_dataset_up_to_date
true true

Or you can completely refresh the existing Vietnamese provinces table in your database by unlink all of your references, then drop these provinces tables and re-create and import all the provinces dataset, then re-establish the relationship between your data and the provinces table again.

I saw some issues in the SQL patch?

If you see any improvement that can be made, please kindly Open a issue and write down your finding. Or even better by Create a Pull Request. Any contribution is welcomed.

I prefer a JSON version

Please see daohoangson/dvhcvn as the JSON alternative version

Reference

Vietnam Map in the banner by vietcentertourist

vietnamese-provinces-database's People

Contributors

thanglequoc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vietnamese-provinces-database's Issues

New decree patch 938/NQ-UBTVQH15 & 939/NQ-UBTVQH15

Update new decree patches

938/NQ-UBTVQH15

Nghị quyết về việc thành lập thị xã Việt Yên và các phường thuộc thị xã Việt Yên, tỉnh Bắc Giang
Ref: 938/NQ-UBTVQH15

939/NQ-UBTVQH15

Nghị quyết về việc nhập xã Thiệu Phú vào thị trấn Thiệu Hóa và thành lập thị trấn Hậu Hiền thuộc huyện Thiệu Hóa, tỉnh Thanh Hóa
Ref: 939/NQ-UBTVQH15

Update data with new decree 569/NQ-UBTVQH15 and 570/NQ-UBTVQH15

Implement the patch checker

Idea: User using the vietnamese provinces database might not be aware of their current dataset up-to-date status, this issue will aim to create a quick checker SQL script to run and check the status of the current db, and list the specific patches that dataset is currently behind

vietnam gso data question

hey!
can you assist me with a question I have about terms of use for data from the gso for Vietnam? I've sent them several emails and no response. Perhaps you know?

Thank you!
Justin

Create GitHub Actions to verify on any new Pull Requests

Create GitHub actions to trigger on any new pull requests, the workflow should include verification of the dataset script by importing the dataset sql to postgres,mysql, oracle, msserver database docker and verify if this action is successful

Automate the process further with Github Action

This is a brief idea to further automate the process with Github action:

High level detail:

  • A github action cronjob will be executed by a pre-defined schedule (daily-weekly).
  • This cronjob will download the Vietnamese provinces xls sheet from the government general statistic website.
  • Then further action is trigger: convert xls to csv -> invoke the existing golang script, if there's a changes, create a github issue and if possible, produce a Pull request with the updated patch files

Apply data patch

During the attempt to automate the data patch script in #31 , I detect some of the inconsistency in the existing dataset during the comparison
The following data records will need to be adjusted.

code name name_en full_name full_name_en code_name district_code administrative_unit_id
05764 Quân Chu Quan Chu Thị trấn Quân Chu Quan Chu Township quan_chu 171 9
06178 Hoàng Văn Thụ Hoang Van Thu Xã Hoàng Văn Thụ Hoang Van Thu Commune _hoang_van_thu 182 10
11353 Cầu Đất Cau Dat Phường Cầu Đất Cau Dat Ward cau_dat 304 8
12949 Mỹ Lộc My Loc Xã Mỹ Lộc My Loc Commune _my_loc 341 10
18136 Tây Sơn Tay Son Thị trấn Tây Sơn Tay Son Township _tay_son 439 9
19306 Ngư Thủy Ngu Thuy Xã Ngư Thủy Ngu Thuy Commune ngu_thuy_ 457 10
19483 A Dơi A Doi Xã A Dơi A Doi Commune _a_doi 465 10
19780 Đúc Duc Phường Phường Đúc Duc Ward duc 474 8
20482 Tu Xã Tư Tu Commune _tu 505 10
21091 Bình Thanh Binh Thanh Xã Bình Thanh Binh Thanh Commune binh_thanh_ 524 10
24667 Đắk Lao Dak Lao Xã Đắk Lao Dak Lao Commune _dak_lao 663 10
25180 Phước Cát Phuoc Cat Thị trấn Phước Cát Phuoc Cat Township phuoc_cat_ 683 9
27460 An Lạc An Lac Phường An Lạc An Lac Ward _an_lac 777 8
28945 Bình Khánh Binh Khanh Xã Bình Khánh Binh Khanh Commune binh_khanh_ 833 10
30949 Hòa Thuận Hoa Thuan Xã Hòa Thuận Hoa Thuan Commune _hoa_thuan 906 10
  • Most of the record are because of improper text trimming that resulted in trailing space.
  • Phường Phường Đúc has incorrect shortname, should be "Phường Đúc", this is caused by improper administrative unit removal during the data creation
  • Quân Chu (05764) to be removed since Quân Chu commune has been merged into Quân Chu township (05851). See: 729/NQ-UBTVQH15
  • Cầu Đất ward code changes from 11353 to 11344

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.