Programming & Development / April 12, 2025

Enum Representation of Districts in Singapore and SQL Table for Storing District Data

Enum District Singapore Java SQL Central Region East Region West Region North Region South Region District Code

Enum Representation in Java

Singapore is divided into 5 main regions. Below is an enum representation of these regions (which are often referred to as districts) with their respective codes:

java

public enum Region {
    CENTRAL_REGION("CR"),
    EAST_REGION("ER"),
    WEST_REGION("WR"),
    NORTH_REGION("NR"),
    SOUTH_REGION("SR");

    private final String code;

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

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

In the code:

  • The enum Region defines the 5 regions of Singapore along with their respective codes.
  • Each region is associated with a two-character abbreviation.
  • The getCode() method allows you to retrieve the region code.

SQL Representation for Storing District Data

To store the regions (districts) of Singapore in a database, you can create a table and insert the data using the following SQL:

sql

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

-- Inserting data for regions of Singapore
INSERT INTO regions (name, code) VALUES
('Central Region', 'CR'),
('East Region', 'ER'),
('West Region', 'WR'),
('North Region', 'NR'),
('South Region', 'SR');

In the SQL:

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

This setup ensures that you can efficiently store and query the regions of Singapore, 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