Te ver doorgevoerde normalisatie
Herinner je de definitie van de tabel loan.
CREATE TABLE loan (
borrower_id INTEGER REFERENCES borrower(id),
bank_id INTEGER REFERENCES bank(id),
approval_date DATE NOT NULL DEFAULT CURRENT_DATE,
gross_approval DECIMAL(9, 2) NOT NULL,
term_in_months SMALLINT NOT NULL,
revolver_status BOOLEAN NOT NULL DEFAULT FALSE,
initial_interest_rate DECIMAL(4, 2) NOT NULL
);
Er is een nieuw ontwerp voor deze tabel voorgesteld om te voldoen aan 1NF. In de herziene tabeldefinitie wordt approval_date vervangen door approval_month, approval_day en approval_year:
CREATE TABLE loan (
...
approval_month SMALLINT,
approval_day SMALLINT,
approval_year SMALLINT,
...
);
Deze oefening laat zien hoe te ver doorgevoerde normalisatie kan toestaan dat ongeldige gegevens worden ingevoegd.
Deze oefening maakt deel uit van de cursus
PostgreSQL-databases maken
Oefeninstructies
- Verwijder de
INSERT INTO-instructie die, als die zou worden uitgevoerd, ertoe zou leiden dat ongeldige gegevens in de tabel worden ingevoegd.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
INSERT INTO loan (
borrower_id, bank_id, approval_month, approval_day,
approval_year, gross_approval, term_in_months,
revolver_status, initial_interest_rate
) VALUES (12, 14, 12, 1, 2013, 421115, 120, false, 4.42);
INSERT INTO loan (
borrower_id, bank_id, approval_month, approval_day,
approval_year, gross_approval, term_in_months,
revolver_status, initial_interest_rate
) VALUES (3, 201, 6, 42, 2017, 30015, 60, true, 3.25);
INSERT INTO loan (
borrower_id, bank_id, approval_month, approval_day,
approval_year, gross_approval, term_in_months,
revolver_status, initial_interest_rate
) VALUES (19, 5, 8, 19, 2018, 200000, 120, false, 6.3);