Programming & Development / April 12, 2025

Enum Representation of Regions in Peru and SQL Table for Storing Region Data

Enum Region Peru Java SQL Amazonas Ancash Apurimac Arequipa Ayacucho Cajamarca Callao Cusco Huancavelica Huanuco Ica Junin La Libertad Lambayeque Lima Loreto Madre de Dios Moquegua Pasco Piura Puno San Martin Tacna Tumbes Ucayali Region Code

Enum Representation in Java

Peru is divided into 26 regions. Below is an enum representation of those regions with their respective codes:

java

public enum Region {
    AMAZONAS("AM"),
    ANCASH("AN"),
    APURIMAC("AP"),
    AREQUIPA("AR"),
    AYACUCHO("AY"),
    CAJAMARCA("CA"),
    CALLAO("CL"),
    CUSCO("CU"),
    HUANCAVELICA("HV"),
    HUANUCO("HN"),
    ICA("IC"),
    JUNIN("JU"),
    LA_LIBERTAD("LL"),
    LAMBAYEQUE("LB"),
    LIMA("LI"),
    LORETO("LO"),
    MADRE_DE_DIOS("MD"),
    MOQUEGUA("MQ"),
    PASCO("PS"),
    PIURA("PI"),
    PUNO("PU"),
    SAN_MARTIN("SM"),
    TACNA("TA"),
    TUMBES("TU"),
    UCAYALI("UC");

    private final String code;

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

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

In the code:

  • The enum Region defines the regions of Peru and 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 Region Data

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

sql

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

-- Inserting data for regions of Peru
INSERT INTO regions (name, code) VALUES
('Amazonas', 'AM'),
('Ancash', 'AN'),
('Apurimac', 'AP'),
('Arequipa', 'AR'),
('Ayacucho', 'AY'),
('Cajamarca', 'CA'),
('Callao', 'CL'),
('Cusco', 'CU'),
('Huancavelica', 'HV'),
('Huanuco', 'HN'),
('Ica', 'IC'),
('Junin', 'JU'),
('La Libertad', 'LL'),
('Lambayeque', 'LB'),
('Lima', 'LI'),
('Loreto', 'LO'),
('Madre de Dios', 'MD'),
('Moquegua', 'MQ'),
('Pasco', 'PS'),
('Piura', 'PI'),
('Puno', 'PU'),
('San Martin', 'SM'),
('Tacna', 'TA'),
('Tumbes', 'TU'),
('Ucayali', 'UC');

In the SQL:

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

This structure allows you to efficiently store and query the regions of Peru in both an application (via Java enum) and a 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