Integrity: the rules that keep data believable
Data integrity means the data is accurate, consistent and complete. A database enforces it through rules, so that invalid data is refused at the point of entry rather than discovered in a report six months later.
Three kinds of integrity rule are named in the syllabus.
- Entity integrity — every primary key must be present and unique. No record may exist without an identity, and no two may share one.
- Referential integrity — a foreign key must either be empty or match an existing primary key. You cannot enrol a student who does not exist, and you cannot delete a class while students still refer to it.
- Domain integrity — every value must be valid for its field: the right data type, within an allowed range, matching a required format, or drawn from a permitted list.
What referential integrity prevents
Without it, deleting a class leaves student records pointing at a class that no longer exists — an orphaned record. Reports then show students in "class 7", which cannot be looked up. The DBMS prevents this by refusing the deletion, or by cascading it, or by setting the foreign keys to null; which of the three is a design decision, but doing nothing is not an option.
Validation and verification are different things
Validation is an automatic check that data is reasonable. Verification is a check that data was entered correctly. Neither guarantees the data is true, and the distinction is examined every year.
A date of birth of 1899 fails validation because it is unreasonable. A date of birth typed as 1995 instead of 1985 passes every validation check there is — it is a perfectly reasonable date — and only verification, such as double entry or reading it back to the person, would catch it.
| Check | Rejects | Example |
|---|---|---|
| Range check | values outside allowed limits | mark must be 0–100 |
| Type check | the wrong data type | age must be a number |
| Format check | the wrong pattern | CNIC as 5 digits, 7 digits, 1 digit |
| Presence check | an empty required field | name must not be blank |
| Length check | too few or too many characters | password 8–16 characters |
| Lookup check | a value not in a permitted list | class must be an existing class |
The three anomalies
A badly structured table misbehaves in three specific ways, and normalisation exists to remove them. Naming the anomaly is usually worth a mark.
An insertion anomaly means you cannot record one fact without knowing another. If teacher details live in the enrolment table, a newly hired teacher cannot be recorded until a student enrols with them. A deletion anomaly means removing one fact destroys another: deleting the last enrolment for that teacher erases their phone number entirely. An update anomaly means one change must be made in many rows, and missing one leaves the database contradicting itself.
Start at Unnormalised and step forward. Watch TeacherPhone: it is repeated on every row until 3NF moves it to its own table, after which changing a phone number is one edit in one place.
The three normal forms
Normalisation is the process of restructuring tables to remove those anomalies. Each form fixes one kind of dependency, and each assumes the previous form has been reached.
Normalise to 3NF: ORDER(OrderNo, ProductCode, ProductName, Quantity, CustomerID, CustomerName).
- Every cell already holds a single value, so the table is in 1NF.Check this first — if a cell held "shirt, tie" the split would have to come before anything else.
- The key is OrderNo + ProductCode. ProductName depends only on ProductCode, and CustomerName only on OrderNo — partial dependencies.Each depends on part of the key rather than all of it, which is what 2NF forbids.
- Split them out: PRODUCT(ProductCode, ProductName) and ORDER(OrderNo, CustomerID, CustomerName), leaving ORDERLINE(OrderNo, ProductCode, Quantity). Now 2NF.Quantity genuinely needs both keys, so it stays in the linking table.
- In ORDER, CustomerName depends on CustomerID, which is not the key — a transitive dependency.OrderNo → CustomerID → CustomerName is a chain through a non-key field.
- Split again: CUSTOMER(CustomerID, CustomerName) and ORDER(OrderNo, CustomerID). Now 3NF.Four tables, each fact stored once, and a customer changing their name is a single edit.
PRODUCT, CUSTOMER, ORDER and ORDERLINE — four tables in 3NF.
Partial and transitive are not the same
A partial dependency is on part of a composite key — so it cannot exist at all if the primary key is a single field. A transitive dependency is on a non-key field, and can exist whatever the key looks like. Students frequently claim a partial dependency in a table with a single-field key, which is impossible by definition.
Before you leave this chapter
- Entity integrity: primary keys present and unique. Referential: foreign keys must match. Domain: values valid for the field.
- Validation checks that data is reasonable; verification checks it was entered correctly. Neither proves it is true.
- Insertion, deletion and update anomalies are what normalisation removes.
- 1NF no repeating groups; 2NF no partial dependency; 3NF no transitive dependency.
- A partial dependency requires a composite key; a transitive one does not.