liveBook · Manning

Data integrity

As explained in Grokking Software Architecture

Data integrity is the preservation of data's accuracy, completeness, consistency, and intended state.

Data integrity means keeping data accurate, complete, consistent, and in its intended state. Think of a database as a guard dog: it should stop an order from pointing to a customer who does not exist, rather than let a ghost customer haunt the records. section 8.2.1

In a relational database, a strict schema defines the structure of tables up front. Built-in constraints reject invalid writes, keeping bad or incomplete data out of storage. section 8.2.1

Keys provide two important guardrails:

  • A primary key identifies each row. Its value must be unique and cannot be null. section 8.2.1
  • A foreign key explicitly links a column to a primary key in another table. Naming a column CustomerId is not enough: the constraint must be created for the database to enforce the link. section 8.2.1

Orders and customers

An Orders table can use CustomerId as a foreign key to Customers.Id. The database then refuses an order for a nonexistent customer, preventing an orphaned record. The constraint also acts as a safety net against deleting a customer who still has open orders. section 8.2.1

Figure 8.2 Showing how Primary Keys and Foreign Keys work together to link tables. The child table (Orders) uses the Customer_ID as a Foreign Key to point directly back to its parent record (Customers), establishing a clear one-to-many relationship.

See how primary and foreign keys connect customers to their orders. section 8.2.1

Normalization supports a clearer structure: store a customer’s address once in an Address table and link to it instead of duplicating it in every order. Integrity is also an architectural constraint: a quick internal tool may trade scalability for speed, but finance and healthcare can make integrity non-negotiable. section 8.2.1 section 2.5.1

How Grokking Software Architecture covers it

How deep it goes
Defines keys and explains database-enforced guardrails, without showing their SQL implementation.
Examples
Uses customer orders and a separately stored address to illustrate relationships and reduced duplication.
What you can do after
Evaluate data integrity constraints when comparing database designs and architectural tradeoffs.
How it connects
Connects data integrity to strict schemas, relational normalization, primary keys, and foreign keys.

Also explained in

Compare how 21 books explain data integrity →

Related concepts

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