Database Design and Normalization
Database Design: From Data Models to Implementable Tables
Turning relations and entities into database tables
A conceptual data model identifies the information a database must represent, but it does not yet specify everything needed to build the database. A relation can be represented as an entity in an entity-relationship model, but implementation requires additional decisions about columns, keys, data types, and integrity rules.
A typical implementation process includes:
Create a table for each entity in the data model.
Define a primary key for every table. The primary key uniquely identifies each row.
Add columns corresponding to the entity’s attributes.
Specify column properties, including:
Data type: For example, integer, floating-point number, text, or date-time.
Nullability: Whether a column is allowed to contain a missing or unknown value.
Default value: A value the database supplies when an insert does not provide one.
Constraints: Rules that limit valid values and help preserve data integrity.
Review normalization and performance needs. The table design may need to be revised to avoid anomalies or, when justified, to improve query performance.
Constraints can require that values fall within a range, belong to a predefined set, or satisfy other business rules. These restrictions help prevent invalid data from entering the database.
Normalization and modification anomalies
Normalization is the process of structuring data into tables so that each fact is stored in an appropriate place. A major goal is to reduce modification anomalies: problems that arise when data is inserted, changed, or deleted.
Insertion anomalies
An insertion anomaly occurs when a table’s structure makes it difficult to add one fact without also providing another unrelated fact.
If a customer table also stores information about cars, a customer who does not own a car may have to be entered with empty car-related fields.
If an existing car is recorded again for a new customer, inconsistent spelling or formatting may be introduced.
Update anomalies
An update anomaly occurs when the same fact is stored in multiple rows and must be changed everywhere.
For example, if a car’s identifier is repeated for every customer who owns that type of car, changing that identifier requires updating every relevant row. If only some rows are changed, the database contains conflicting information.
Deletion anomalies
A deletion anomaly occurs when deleting one fact unintentionally removes another fact that should be retained.
For example, if a customer’s row is the only place where a particular car type is recorded, deleting that customer may also erase the database’s only record that the car type exists.
How normalization helps
A table containing information about two distinct concepts—such as customers and cars—can often be divided into separate tables. This makes it possible to add, update, or delete information about one concept without unintentionally changing information about the other.
Properly normalized tables reduce redundant storage and help prevent insertion, update, and deletion anomalies.
Functional dependencies, determinants, and candidate keys
A functional dependency describes a relationship between attributes in which the value of one attribute determines the value of another attribute or group of attributes.
If knowing attribute A is sufficient to determine attribute B, the dependency is written as A→B. Attribute B is functionally dependent on A.
A determinant is an attribute, or set of attributes, that determines the values of other attributes in a relation. In A→B, A is the determinant.
A candidate key is a minimal attribute, or minimal combination of attributes, that uniquely identifies a row. Candidate keys include:
Simple candidate keys: A single attribute uniquely identifies a row.
Composite candidate keys: Two or more attributes together uniquely identify a row.
A table’s primary key is selected from its candidate keys. Other candidate keys may also be enforced as unique constraints.
Normal forms
Normal forms are guidelines for evaluating and improving table structures.
First Normal Form
A relation is in First Normal Form (1NF) when its attributes contain values in the required relational form—for example, each field contains a single value rather than a repeating group of values.
Second Normal Form
A table is in Second Normal Form (2NF) when it is in 1NF and has no partial dependencies. A partial dependency occurs when a non-key attribute depends on only part of a composite candidate key rather than on the full key.
Third Normal Form
A table is in Third Normal Form (3NF) when it is in 2NF and has no transitive dependencies of non-key attributes on a key. A transitive dependency occurs when a key determines one non-key attribute, which in turn determines another non-key attribute.
Boyce–Codd Normal Form
A table is in Boyce–Codd Normal Form (BCNF) when every determinant is a candidate key or, more generally, a superkey. BCNF is stricter than 3NF and is sometimes informally called “3.5 normal form.”
Additional forms include Fourth, Fifth, Domain-Key, and Sixth Normal Form. For many practical designs, 3NF or BCNF is an adequate target. These levels generally eliminate the modification anomalies that normalization is intended to prevent.
Normalization example: customers, postal codes, and accountants
Suppose a customer table contains:
Customer ID
Customer name and address
City, state, and postal code
Accountant ID
Accountant name and phone number
The table has dependencies that do not all originate directly from the customer ID:
A postal code determines a city and state.
An accountant ID determines the accountant’s name and phone number.
If all these facts are stored in the customer table, postal-code and accountant information is repeated for multiple customers. That repetition can lead to update inconsistencies and other anomalies.
A normalized design separates the concepts into three tables:
Customer table
Primary key: Customer ID
Other attributes: Customer name and address
Foreign keys: Postal code and accountant ID
Postal code table
Primary key: Postal code
Other attributes: City and state
Accountant table
Primary key: Accountant ID
Other attributes: Accountant name and phone number
The foreign keys connect each customer to the appropriate postal-code and accountant records. Each fact is stored in the table whose key determines it.
Denormalization
Denormalization deliberately combines information from separate tables or adds redundant data to a design. It may be used when there is a defensible business reason, especially to improve query speed or simplify commonly used queries.
For example, a normalized design might store postal codes in a separate table containing the corresponding city and state. A denormalized customer table could instead store the postal code, city, and state together. A query retrieving a customer’s address could then read one table rather than joining the customer and postal-code tables.
Potential benefits
Faster queries: Avoiding joins can improve performance for queries that frequently need the combined information.
Simpler queries: Applications may need fewer joins and less complex SQL.
Simpler apparent structure: A design with fewer tables may be easier to understand for some uses.
Costs and risks
Denormalization increases redundancy and reintroduces the possibility of modification anomalies.
Repeated data: The same city and state may appear in many customer rows.
Inconsistent values: Users may enter “California,” “CA,” or different letter cases for the same state.
More complicated maintenance: Rules or application checks may be needed to keep duplicated values synchronized.
Constraints and software validation can reduce these risks, but they add implementation and maintenance overhead.
Denormalization should be based on a measurable or otherwise defensible business need. Its performance or simplicity benefits must be weighed against the extra risk of inconsistent data.
Implementing one-to-one relationships
A one-to-one relationship links a row in one table to at most one row in another table, and vice versa. The relationship is implemented by placing a foreign key in one of the tables.
Choosing a table for the foreign key depends on participation requirements and on which representation is most useful.
When participation is optional on both sides
If either entity may exist without participating in the relationship, either table can hold the foreign key. The designer can choose the placement that makes the data model most natural.
For example, employees and lockers may have an optional one-to-one relationship: an employee may have no locker, and a locker may be unassigned. The foreign key could be placed in the employee table or the locker table, depending on the preferred design.
When participation is mandatory on one side
When every row of one entity must participate but rows of the other entity may not, storing the foreign key on the mandatory-participation side can avoid unnecessary null foreign-key values.
For example, if every hospital patient must be assigned to a bed, but a bed may be empty, the patient table can contain a bed ID as a foreign key. An empty bed then does not require a patient row to reference it.
Enforcing the one-to-one rule
A foreign key alone does not necessarily enforce a one-to-one relationship. If multiple rows can contain the same foreign-key value, the relationship may behave as one-to-many. A uniqueness constraint on the foreign key is commonly needed to ensure that each referenced row is associated with no more than one row on the other side.
Querying a one-to-one relationship
A query joins the tables by matching the foreign key to the corresponding primary key. The direction of the join condition depends on which table contains the foreign key.
For example, if Employee.LockerID references Locker.LockerID, the join condition matches those two columns. If instead Locker.EmployeeID references Employee.EmployeeID, the condition matches the employee IDs.
Implementing one-to-many relationships
In a one-to-many relationship, one row on the “one” side can be associated with many rows on the “many” side. The foreign key belongs in the table on the many side.
The “one” side is commonly called the parent table, and the “many” side is called the child table.
For example:
A team may have zero or many players.
Each player belongs to one team.
The team table contains the team’s primary key. The player table stores that key as a foreign key. This allows multiple player rows to reference the same team.
Queries combine the tables by matching the team’s primary key to the foreign key in the player table. SQL can express this join using a JOIN clause or an equivalent condition in the WHERE clause.
Implementing many-to-many relationships
A many-to-many relationship cannot be represented directly by placing a single foreign key in either parent table. Instead, it requires an intersection table, also called a junction or linking table.
For example:
A student can take many classes.
A class can contain many students.
A Student_Class intersection table links the student and class tables. A row in the intersection table represents one student–class association.
Composite primary key
A common design uses a composite primary key made from the primary keys of the two parent tables:
Student ID
Class number
Each component is also a foreign key to its parent table. Together, the two values identify the association row and prevent the same student–class pair from appearing more than once.
To list students and the classes they take, a query joins:
The student table to the intersection table by student ID.
The intersection table to the class table by class number.
Associative entities
An intersection table that stores additional information about the relationship is called an associative entity or associative table.
For example, a student–class table may include a grade. The grade does not describe only the student or only the class; it describes the specific student’s participation in that class.
Composite keys versus surrogate keys
An associative entity can instead use a surrogate key, such as RatingID, as its primary key. The parent-table keys then remain foreign keys but are no longer part of the primary key.
The choice affects whether the same parent pair can appear more than once:
Composite key: Each pair of parent identifiers can occur at most once.
Surrogate key: The same pair can occur multiple times unless an additional uniqueness constraint prevents it.
For example, a customer–product rating table with a composite key of Customer ID and Product ID permits each customer to rate each product only once. If the table uses a separate Rating ID as its primary key, a customer–product pair can appear repeatedly, allowing multiple ratings by the same customer for the same product.
If repeated pairs are not allowed, a unique constraint on the combination of the two foreign keys can preserve that rule even when the table has a surrogate primary key.
Recursive relationships
A recursive relationship occurs when a table is related to itself. Its rows represent entities of the same type, but one row is associated with another row in that same table.
The implementation depends on the relationship’s cardinality:
A one-to-one or one-to-many recursive relationship generally uses a foreign key in the same table.
A many-to-many recursive relationship requires an intersection table.
One-to-one recursive relationships
A one-to-one recursive relationship can be represented with a foreign key that refers to the primary key of the same table.
For a sponsorship relationship between people, a person table could store the ID of the person who sponsored each person. Alternatively, it could store the ID of the person each row sponsors. The choice depends on which direction best represents the required information.
To enforce a strict one-to-one relationship, the self-referencing foreign key may need a uniqueness constraint, in addition to any required nullability rules.
One-to-many recursive relationships
A one-to-many recursive relationship also uses a self-referencing foreign key.
For example, in a customer-referral relationship, one customer may refer many other customers, while each customer is referred by at most one other customer. The customer table can contain a ReferredByCustomerID column that refers to another row’s Customer ID.
To find the customers referred by a particular customer, the table is joined to itself. Each reference to the table receives a different alias:
SELECT referred.CustomerID, referred.Name
FROM Customer AS referrer
JOIN Customer AS referred
ON referred.ReferredByCustomerID = referrer.CustomerID
WHERE referrer.CustomerID = 100;The aliases let the query distinguish the row representing the referrer from rows representing the referred customers, even though both come from the same table.
Many-to-many recursive relationships
A many-to-many recursive relationship links multiple rows in a table to multiple other rows of that same table. It requires an intersection table whose two foreign keys both reference the same parent table.
For example, if doctors can treat other doctors, an intersection table could store:
The ID of the treating doctor
The ID of the doctor receiving treatment
The query joins the doctor table twice—once under an alias for each role—and joins each alias to the appropriate foreign key in the intersection table. This produces pairs of doctors connected by the treatment relationship.
Recursive joins work by treating each role in the relationship as a separate instance of the same table. Aliases make those roles explicit, while self-referencing foreign keys or intersection tables encode the relationships in the database.

Ask anything
We've read this whole study set, so questions about it get the best answers.