Programming & Development / April 12, 2025

Enum Representation of Provinces in Saudi Arabia and SQL Table for Storing Province Data

Enum Province Saudi Arabia Java SQL Makkah Riyadh Eastern Province Madinah Asir Province Code

Enum Representation in Java

Saudi Arabia is divided into 13 provinces. Below is an enum representation of these provinces with their respective codes:

java

public enum Province {
    RIYADH("RI"),
    MAKKAH("MA"),
    MADINAH("MD"),
    EASTERN_PROVINCE("EP"),
    ASIR("AS"),
    QASSIM("QA"),
    HA'IL("HA"),
    JOUF("JU"),
    NAJRAN("NJ"),
    TABUK("TA"),
    BAHA("BA"),
    JIZAN("JI"),
    AL-QUWAY'IAH("AQ");

    private final String code;

    Province(String code) {
        this.code = code;
    }

    public String getCode() {
        return this.code;
    }
}

In the code:

  • The enum Province defines the 13 provinces of Saudi Arabia along with their respective codes.
  • Each province is associated with a two-character abbreviation.
  • The getCode() method allows you to retrieve the province code.

SQL Representation for Storing Province Data

To store the provinces of Saudi Arabia in a database, you can create a table and insert the data using the following SQL:

sql

-- Table definition for storing provinces of Saudi Arabia
CREATE TABLE provinces (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    code CHAR(2) NOT NULL
);

-- Inserting data for provinces of Saudi Arabia
INSERT INTO provinces (name, code) VALUES
('Riyadh', 'RI'),
('Makkah', 'MA'),
('Madinah', 'MD'),
('Eastern Province', 'EP'),
('Asir', 'AS'),
('Qassim', 'QA'),
('Ha\'il', 'HA'),
('Jouf', 'JU'),
('Najran', 'NJ'),
('Tabuk', 'TA'),
('Baha', 'BA'),
('Jizan', 'JI'),
('Al-Quway\'iah', 'AQ');

In the SQL:

  • We define a provinces table with columns id (auto-incremented), name (the name of the province), and code (the abbreviation for the province).
  • The INSERT INTO statement adds the provinces of Saudi Arabia along with their respective codes into the table.

This setup ensures that you can efficiently store and query the provinces of Saudi Arabia, both in your Java application (via enums) and in a relational database system.


Comments

No comments yet

Add a new Comment

NUHMAN.COM

Information Technology website for Programming & Development, Web Design & UX/UI, Startups & Innovation, Gadgets & Consumer Tech, Cloud Computing & Enterprise Tech, Cybersecurity, Artificial Intelligence (AI) & Machine Learning (ML), Gaming Technology, Mobile Development, Tech News & Trends, Open Source & Linux, Data Science & Analytics

Categories

Tags

©{" "} Nuhmans.com . All Rights Reserved. Designed by{" "} HTML Codex