Ir al contenido principal

Integrity constraints for relational databases

When we want to create a relational database, we must comply with four integrity constraints in order for our DB to work correctly.

  1. Entity integrity constraint. A PK (Primary Key) cannot allow null values
    • Enforcement: check for null values when enter data.
  2. Key integrity constraint. No two tuples can have the same attribute value.
    • Enforcement: check duplicity.
  3. Referential integrity constraint. We cannot have any unmatched FK (Foreign Key). That is, if B references A, A must exist.
    • Enforcement:
      • Restriction. The Update/delete of PK is restricted to not having a matching FK.
      • Nullification. Update/delete of PK can only be done after setting any FK to null.
      • Cascading. Update/delete of PK cascades to any FK.
  4. Semantic integrity constraint. We must use data that makes sense. We look for semantic correctness.
    • Enforcement: use restrictions when enter data such as: length, legal values (i.e. car brands), types of data (i.e. currency, date, etc.), range, etc.

Comentarios