Lepší kvalita dat pomocí omezení

Introduction to Relational Databases in SQL

Timo Grossenbacher

Data Journalist

Omezení integrity

  1. Omezení atributů, např. datové typy sloupců (kapitola 2)
  2. Omezení klíčů, např. primární klíče (kapitola 3)
  3. Omezení referenční integrity, vynucená cizími klíči (kapitola 4)
Introduction to Relational Databases in SQL

Proč omezení?

  • Omezení dávají datům strukturu
  • Omezení podporují konzistenci, a tím kvalitu dat
  • Kvalita dat je výhodou pro business i předpokladem datové vědy
  • Vynucení je náročné, ale PostgreSQL pomáhá
Introduction to Relational Databases in SQL

Datové typy jako omezení atributů

Introduction to Relational Databases in SQL

Práce s datovými typy (přetypování)

CREATE TABLE weather (
 temperature integer,
 wind_speed text);

SELECT temperature * wind_speed AS wind_chill FROM weather;
operator does not exist: integer * text
HINT: No operator matches the given name and argument type(s). 
You might need to add explicit type casts.
SELECT temperature * CAST(wind_speed AS integer) AS wind_chill
FROM weather;
Introduction to Relational Databases in SQL

Pojďme si procvičit!

Introduction to Relational Databases in SQL

Preparing Video For Download...