Overview
The meteorological database uses a normalized schema to store weather observations from various Colombian cities. The design focuses on data integrity through constraints and ensures uniqueness of measurements per location and time.Database Structure
Database Creation
Clima Table
Theclima table is the core entity that stores hourly weather observations.
Table Definition
Field Definitions
Primary Key
| Field | Type | Description |
|---|---|---|
id | BIGINT AUTO_INCREMENT | Unique identifier for each weather observation. Uses BIGINT to support large-scale data collection over time. |
Location Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
localidad | VARCHAR(100) | NOT NULL | City or locality name where the measurement was taken |
pais | VARCHAR(50) | NOT NULL DEFAULT 'Colombia' | Country name with a default value for Colombian observations |
Measurement Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
tempCelsius | DECIMAL(5,2) | NOT NULL | Temperature in Celsius. Supports values from -999.99 to 999.99°C |
fechaHora | DATETIME | NOT NULL | Timestamp of the observation with date and time precision |
coberturaNubes | VARCHAR(20) | NOT NULL, CHECK constraint | Cloud coverage: ‘Minima’, ‘Parcial’, or ‘Total’ |
indiceUv | DECIMAL(4,2) | Optional | UV index measurement (0-99.99) |
presionAtmosferica | DECIMAL(7,2) | Optional | Atmospheric pressure in hPa/mb (up to 99999.99) |
velocidadVientoNudos | DECIMAL(5,2) | Optional | Wind speed in knots (up to 999.99) |
Constraints
PRIMARY KEY
id field serves as the surrogate primary key, automatically incrementing for each new record.
UNIQUE Constraint
CHECK Constraint
'Minima'- Minimal cloud coverage'Parcial'- Partial cloud coverage'Total'- Total/complete cloud coverage
NOT NULL Constraints
Critical fields that must always have values:localidad- Location is mandatory for contextpais- Country defaults to ‘Colombia’ but cannot be NULLtempCelsius- Temperature is the primary measurementfechaHora- Timestamp is essential for temporal analysiscoberturaNubes- Cloud coverage is a required observation
Design Decisions
1. BIGINT for Primary Key
Rationale: Weather data accumulates rapidly. A BIGINT supports up to 9,223,372,036,854,775,807 records, ensuring the system can handle decades of hourly observations from multiple locations.2. DECIMAL for Numeric Measurements
Rationale: Using DECIMAL instead of FLOAT ensures precise storage of measurements without floating-point rounding errors. This is critical for scientific accuracy.DECIMAL(5,2)for temperature: -999.99 to 999.99°CDECIMAL(4,2)for UV index: 0 to 99.99DECIMAL(7,2)for pressure: up to 99999.99 hPa
3. Composite UNIQUE Constraint
Rationale: The combination of(localidad, fechaHora) ensures data integrity while allowing:
- Multiple measurements for the same location at different times
- Multiple locations measured at the same time
- Prevention of duplicate entries
4. Optional Environmental Fields
Rationale: Fields likeindiceUv, presionAtmosferica, and velocidadVientoNudos are optional because:
- Not all weather stations may have these sensors
- Some observations might have incomplete data
- Allows flexibility in data collection while maintaining core measurements
5. DEFAULT Value for Country
Rationale: Since the system primarily serves Colombian locations, settingDEFAULT 'Colombia' reduces data entry overhead while maintaining the flexibility to record international observations.
6. VARCHAR Sizing
Rationale:localidad VARCHAR(100)- Accommodates long city namespais VARCHAR(50)- Sufficient for country namescoberturaNubes VARCHAR(20)- Sized for the longest valid value (‘Parcial’)