Skip to content

alpersamur3/turkey-locations-sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🇹🇷 Turkey Province / District / Neighborhood Database

Türkiye İl · İlçe · Mahalle – Excel → SQL Converter & Database Generator

Python MSSQL PostgreSQL MySQL SQLite

Complete Turkey administrative divisions database – All 81 provinces, 922 districts (+51 auto-generated province centers = 973 total) and 32,296 neighborhoods with SQL ready to import.

Türkiye'nin tüm idari bölünme verisi – 81 il, 922 ilçe (+51 otomatik il merkezi = 973 toplam) ve 32.296 mahalle verisiyle doğrudan SQL aktarım.


English · Türkçe


📸 Screenshots / Ekran Görüntüleri

Tablo & Kolon Ayarları Dosya Seçimi SQL Oluşturma
Tablo Ayarları Dosya Seçimi SQL Oluşturma

🇬🇧 English

📌 Overview

A desktop GUI application that reads Turkey's official province (İl), district (İlçe) and neighborhood (Mahalle) data from Excel files and generates SQL scripts for 4 different database engines. You can export as .sql file or push directly to your database.

📋 Data Source

This project is built on the official data published by the Republic of Turkey – Ministry of Interior:

🔗 e-İçişleri – Mülki İdari Bölümler (Administrative Divisions)

All default column mappings and row offsets are calibrated to the Excel format provided on this official government website.

📦 Ready-to-Use SQL / Hazır SQL Dosyası

If you don't want to run the tool, a pre-generated MSSQL script is available in the 2026TurkeySQL/ directory:

File Engine Date Description
2026TurkeySQL/*.sql MSSQL 13.03.2026 Complete Turkey İl/İlçe/Mahalle data – ready to execute

Simply run this .sql file on your MSSQL server to get the full database without running the tool.

✨ Features

Feature Description
4 SQL Engines SQLite, PostgreSQL, MySQL, Microsoft SQL Server
GUI Interface 4-tab Tkinter application – no command line needed
Customizable Schema Table names, column names, data types, lengths, NULL constraints
Live Schema Preview Real-time DDL preview as you change settings
Auto "İl Merkezi" District 51 province centers auto-created – neighborhoods bound to a province center (not a named district) automatically get a synthetic district record (e.g. "Adıyaman İl Merkezi") inserted into the district table so that IlceId is never NULL
IF NOT EXISTS Safe re-runs – tables are only created if they don't already exist
SQL File Export Save generated SQL as .sql file
Direct DB Push Write directly to your database via connection string
Excel Compat Supports .xls (legacy) and .xlsx / .xlsm formats

🔄 Auto "İl Merkezi" (Province Center) District

Some neighborhoods in the source data are linked directly to a province instead of a specific district (e.g. ADIYAMAN -> ADIYAMAN-İL MERKEZİ). When this happens, the tool automatically creates a district record named "{Province} İl Merkezi" in the district (İlçe) table with a unique ID and links all affected neighborhoods to it. This ensures:

  • IlceId column is never NULL in the neighborhood table
  • ✅ Referential integrity is maintained across all foreign keys
  • ✅ The auto-created districts are clearly marked with -- Otomatik oluşturulan İl Merkezi ilçeleri comment in SQL output

📁 Project Structure

tr/
├── main.py                          # Entry point
├── README.md
├── requirements.txt
├── 2026TurkeySQL/                   # Pre-generated MSSQL script (13.03.2026)
│   └── *.sql
└── src/
    ├── __init__.py
    ├── deps.py                      # Dependency management
    ├── utils.py                     # Turkish character helpers
    ├── parsers/
    │   ├── __init__.py
    │   ├── excel_reader.py          # Excel file reader (.xls/.xlsx)
    │   ├── il_parser.py             # Province parser
    │   ├── ilce_parser.py           # District parser
    │   └── mahalle_parser.py        # Neighborhood parser
    ├── generators/
    │   ├── __init__.py
    │   └── sql_generator.py         # SQL generator (DDL + DML)
    ├── db/
    │   ├── __init__.py
    │   └── push.py                  # Database push handler
    └── gui/
        ├── __init__.py
        ├── constants.py             # GUI constants
        └── app.py                   # Main application window

🚀 Installation & Usage

Requirements

  • Python 3.8+
  • Tkinter (bundled with Python)

Install Dependencies

pip install -r requirements.txt

Run

python main.py

Quick Start

  1. Tab 1 – Select SQL engine, customize table/column names if needed
  2. Tab 2 – Select the 3 Excel files downloaded from e-İçişleri
  3. Tab 3 – Click "Verileri Oku & SQL Oluştur" → preview & export SQL
  4. Tab 4 – Enter connection string → click "DB'ye Aktar" to push

⚙️ Connection String Examples

Engine Example
SQLite C:\database.db
PostgreSQL host=localhost dbname=mydb user=postgres password=xxx
MySQL host=localhost;port=3306;user=root;password=xxx;database=mydb
MSSQL Server=94.x.x.x;Database=myDb;User Id=user;Password=pwd;

🇹🇷 Türkçe

📌 Genel Bakış

Türkiye'nin resmi il, ilçe ve mahalle verilerini Excel dosyalarından okuyarak 4 farklı veritabanı motoruna uygun SQL scriptleri oluşturan masaüstü GUI uygulaması. Oluşturulan SQL'i .sql dosyası olarak dışa aktarabilir veya doğrudan veritabanınıza yazabilirsiniz.

📋 Veri Kaynağı

Bu proje, T.C. İçişleri Bakanlığı tarafından yayımlanan resmi Mülki İdari Bölümler verisini kullanmaktadır:

🔗 e-İçişleri – Mülki İdari Bölümler

Varsayılan sütun ve satır ayarları bu sitedeki Excel formatına göre kalibre edilmiştir.

📦 Hazır SQL Dosyası

Aracı çalıştırmak istemiyorsanız, 2026TurkeySQL/ dizininde MSSQL için hazır SQL scripti mevcuttur:

Dosya Motor Tarih Açıklama
2026TurkeySQL/*.sql MSSQL 13.03.2026 Tüm Türkiye İl/İlçe/Mahalle verisi – doğrudan çalıştırılabilir

Bu .sql dosyasını MSSQL sunucunuzda çalıştırarak aracı kullanmadan tüm veritabanını elde edebilirsiniz.

✨ Özellikler

Özellik Açıklama
4 SQL Motoru SQLite, PostgreSQL, MySQL, Microsoft SQL Server
GUI Arayüzü 4 sekmeli Tkinter uygulaması – komut satırı gerektirmez
Özelleştirilebilir Şema Tablo adları, kolon adları, veri tipleri, uzunluklar, NULL kısıtlamaları
Canlı Şema Önizlemesi Ayarları değiştirdikçe DDL anlık güncellenir
Otomatik "İl Merkezi" İlçesi 51 il merkezi otomatik oluşturulur – il merkezine bağlı mahalleler için ilçe tablosuna otomatik kayıt oluşturulur (örn: "Adıyaman İl Merkezi"), böylece IlceId asla NULL olmaz
IF NOT EXISTS Tekrar çalıştırmada hata vermez – tablolar sadece yoksa oluşturulur
SQL Dosyası Dışa Aktarma Oluşturulan SQL'i .sql olarak kaydedin
Doğrudan DB Aktarımı Bağlantı dizesiyle doğrudan veritabanına yazın
Excel Uyumluluğu .xls (eski format) ve .xlsx / .xlsm destekler

🔄 Otomatik "İl Merkezi" İlçesi Oluşturma

Kaynak veride bazı mahalleler belirli bir ilçeye değil doğrudan il merkezine bağlıdır (örn: ADIYAMAN -> ADIYAMAN-İL MERKEZİ). Bu durumda uygulama otomatik olarak ilçe tablosuna "{İl Adı} İl Merkezi" adında bir kayıt oluşturur ve etkilenen tüm mahalleleri bu ilçeye bağlar:

  • ✅ Mahalle tablosunda IlceId kolonu asla NULL olmaz
  • ✅ Tüm foreign key referansları sağlam kalır
  • ✅ Otomatik oluşturulan ilçeler SQL çıktısında -- Otomatik oluşturulan İl Merkezi ilçeleri yorumuyla işaretlenir

🚀 Kurulum & Çalıştırma

Gereksinimler

  • Python 3.8+
  • Tkinter (Python ile birlikte gelir)

Bağımlılıkları Yükleme

pip install -r requirements.txt

Çalıştırma

python main.py

Hızlı Başlangıç

  1. Sekme 1 – SQL motoru seçin, tablo/kolon adlarını özelleştirin
  2. Sekme 2e-İçişleri sitesinden indirdiğiniz 3 Excel dosyasını seçin
  3. Sekme 3"Verileri Oku & SQL Oluştur" → SQL'i önizleyin & dışa aktarın
  4. Sekme 4 – Bağlantı dizesini girin → "DB'ye Aktar" butonuyla veritabanına yazın

⚙️ Bağlantı Dizesi Örnekleri

Motor Örnek
SQLite C:\veritabani.db
PostgreSQL host=localhost dbname=mydb user=postgres password=xxx
MySQL host=localhost;port=3306;user=root;password=xxx;database=mydb
MSSQL Server=94.x.x.x;Database=myDb;User Id=user;Password=pwd;

⚠️ Important Notes / Önemli Notlar

English Türkçe
🔢 AUTO INCREMENT is not used – IDs are assigned sequentially starting from 1 AUTO INCREMENT kullanılmaz – ID'ler 1'den başlayarak sırayla atanır
🔄 Tables are created only if they don't exist (IF NOT EXISTS) Tablolar sadece yoksa oluşturulur (IF NOT EXISTS)
🏛️ Unmatched neighborhoods get an auto-generated "İl Merkezi" district record Eşleşmeyen mahalleler için otomatik "İl Merkezi" ilçe kaydı oluşturulur
📊 Data sourced from official e-İçişleri Excel files Veri kaynağı resmi e-İçişleri Excel dosyalarıdır

🗄️ Database Schema / Veritabanı Şeması

┌─────────────────────┐
│      Iller (İl)     │
├─────────────────────┤
│ Id     INT [PK]     │
│ Adi    NVARCHAR(100) │
└────────┬────────────┘
         │ 1:N
         ▼
┌─────────────────────┐
│    Ilceler (İlçe)   │
├─────────────────────┤
│ Id     INT [PK]     │
│ Adi    NVARCHAR(100) │
│ IlId   INT [FK]     │──→ Iller.Id
└────────┬────────────┘
         │ 1:N
         ▼
┌─────────────────────────┐
│   Mahalleler (Mahalle)  │
├─────────────────────────┤
│ Id      INT [PK]        │
│ Adi     NVARCHAR(500)    │
│ IlId    INT [FK]        │──→ Iller.Id
│ IlceId  INT [FK]        │──→ Ilceler.Id
└─────────────────────────┘

Keywords / Anahtar Kelimeler: Turkey provinces SQL, Türkiye il ilçe mahalle veritabanı, Turkey administrative divisions database, Türkiye mülki idari bölümler SQL, Turkey city district neighborhood data, il ilçe mahalle SQL Server, Turkey geography database, Türkiye şehir ilçe mahalle listesi SQL, Turkey MSSQL PostgreSQL MySQL SQLite, e-icisleri mülki idari bölümler excel to sql


📄 License / Lisans: This project is open source. Data is sourced from the Republic of Turkey Ministry of Interior.
Bu proje açık kaynaklıdır. Veri kaynağı T.C. İçişleri Bakanlığı'dır.

About

Turkey province, district & neighborhood database generator – Converts official e-İçişleri Excel data into SQL for MSSQL, PostgreSQL, MySQL and SQLite.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages