8.2. SQL Constraints

8.2.1. Rationale

  • Does something automatically

  • Prevents from duplicating information

  • Prevents from loss of integrity

../../_images/sql-constraints.png
../../_images/sql-literalvalue.png

8.2.2. NOT NULL

  • Ensures that a column cannot have a NULL value

8.2.3. UNIQUE

  • Ensures that all values in a column are different

8.2.4. PRIMARY KEY

  • Uniquely identifies each row in a table

  • A combination of a NOT NULL and UNIQUE

8.2.5. FOREIGN KEY

  • Uniquely identifies a row/record in another table

8.2.6. CHECK

  • Ensures that all values in a column satisfies a specific condition

8.2.7. DEFAULT

  • Sets a default value for a column when no value is specified

8.2.8. INDEX

  • Used to create and retrieve data from the database very quickly

  • Analog to notebook calendar tabs

../../_images/sql-index-notebookcalendar.png