liveBook · Manning

Data integrity

As explained in Grokking Relational Database Design

Data integrity is the property that data remains accurate, complete, valid, trustworthy, and protected from unintended alteration or loss.

Data integrity means keeping data accurate, complete, consistent, and trustworthy throughout its storage and use. In database design, it protects relationships and prevents unintended information loss. section 3.3 section 7.3

Build integrity into the database by checking these design decisions:

  • Give every column an appropriate data type. section 7.3
  • Give every table a primary key. section 7.3
  • Use foreign keys to preserve relationships between tables. section 7.3
  • Base constraints on analyzed requirements. section 7.3

These measures keep values consistent across tables, reduce redundancy, and prevent anomalies. An insertion anomaly forces unrelated data into a new record; an update anomaly creates conflicting values; a delete anomaly unintentionally removes information. section 3.3

Connecting authors and books

Suppose a publishing application stores authors and books in related tables. A book table with author_id but no foreign key can contain an orphan record that refers to a nonexistent author. Add a constraint so author_id must reference author(author_id). section 7.3

CREATE TABLE book (
    book_id INT PRIMARY KEY,
    title VARCHAR(200) NOT NULL,
    author_id INT NOT NULL,
    CONSTRAINT FK_author_id
      FOREIGN KEY (author_id)
      REFERENCES author(author_id)
  );

Inspect the corrected SQL definition, which adds a foreign key from book.author_id to author.author_id. section 7.3

Review integrity repeatedly during database design and implementation. Small omissions, such as forgetting a foreign key, can make a database harder to manage and secure. section 3.16 section 7.3

How Grokking Relational Database Design covers it

How deep it goes
Defines integrity, identifies anomalies, and demonstrates a foreign-key correction without detailing every constraint type.
Examples
Uses author and book tables to show how a missing foreign key permits orphan records.
What it assumes
Assumes basic relational database concepts while teaching integrity through tables, relationships, keys, and anomalies.
What you can do after
Apply it via SQL by reviewing keys, data types, relationships, and constraints for integrity gaps.
How it connects
Connects data types, primary keys, foreign keys, constraints, normalization, data consistency, security, and database design.

Also explained in

Compare how 18 books explain data integrity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.