Proiectarea bazelor de date
Lis Sulmont
Curriculum Manager
$$

$$

Scop: cantitatea totală de cărți ale lui Octavia E. Butler vândute în Vancouver în T4 din 2018
SELECT SUM(quantity) FROM fact_booksales
-- Join to get city
INNER JOIN dim_store_star on fact_booksales.store_id = dim_store_star.store_id
-- Join to get author
INNER JOIN dim_book_star on fact_booksales.book_id = dim_book_star.book_id
-- Join to get year and quarter
INNER JOIN dim_time_star on fact_booksales.time_id = dim_time_star.time_id
WHERE
dim_store_star.city = 'Vancouver' AND dim_book_star.author = 'Octavia E. Butler' AND
dim_time_star.year = 2018 AND dim_time_star.quarter = 4;
7600
Total: 3 join-uri
SELECT
SUM(fact_booksales.quantity)
FROM
fact_booksales
-- Join to get city
INNER JOIN dim_store_sf ON fact_booksales.store_id = dim_store_sf.store_id
INNER JOIN dim_city_sf ON dim_store_sf.city_id = dim_city_sf.city_id
-- Join to get author
INNER JOIN dim_book_sf ON fact_booksales.book_id = dim_book_sf.book_id
INNER JOIN dim_author_sf ON dim_book_sf.author_id = dim_author_sf.author_id
-- Join to get year and quarter
INNER JOIN dim_time_sf ON fact_booksales.time_id = dim_time_sf.time_id
INNER JOIN dim_month_sf ON dim_time_sf.month_id = dim_month_sf.month_id
INNER JOIN dim_quarter_sf ON dim_month_sf.quarter_id = dim_quarter_sf.quarter_id
INNER JOIN dim_year_sf ON dim_quarter_sf.year_id = dim_year_sf.year_id
WHERE
dim_city_sf.city = `Vancouver`
AND
dim_author_sf.author = `Octavia E. Butler`
AND
dim_year_sf.year = 2018 AND dim_quarter_sf.quarter = 4;
sum
7600
Total: 8 join-uri
Deci, de ce am dori să normalizăm o bază de date?

Bazele de date denormalizate permit redundanța datelor

Normalizarea elimină redundanța datelor
$$
Trebuie respectate convențiile de denumire datorită integrității referențiale, ex.: „California", nu „CA" sau „california"
Mai puțină redundanță = mai puține înregistrări de modificat
Tabelele mici sunt mai ușor de extins decât cele mari
Normalizarea elimină redundanța datelor: economii de stocare
Integritate mai bună a datelor: date precise și consistente
Ex.: baze de date operaționale
De regulă, înalt normalizate
Ex.: depozite de date
De regulă, mai puțin normalizate
Proiectarea bazelor de date