制約によるデータ品質の向上

SQL リレーショナルデータベース入門

Timo Grossenbacher

Data Journalist

整合性制約

  1. 属性制約(例:列のデータ型(第2章))
  2. キー制約(例:主キー(第3章))
  3. 参照整合性制約(外部キーによって結びつける(第4章 ))
SQL リレーショナルデータベース入門

なぜ制約が必要か?

  • 制約がデータ構造を整える
  • 制約は一貫性とデータ品質の向上に役立つ
  • データ品質はビジネス上の利点でありデータサイエンスの前提条件
  • 適用は困難だが、PostgreSQLが役立つ
SQL リレーショナルデータベース入門

属性制約としてのデータ型

SQL リレーショナルデータベース入門

データ型の変換(CAST)

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;
SQL リレーショナルデータベース入門

練習しましょう!

SQL リレーショナルデータベース入門

Preparing Video For Download...