Mapping Overview
Design Decisions
Read aloud is unavailable in this browser.
Where Algorithms Meet Judgment
The mapping algorithm provides systematic procedures, but at numerous points, it presents choices rather than mandates. These decision points are where database design transitions from mechanical translation to engineering judgment.
Consider: for a 1:1 relationship, should you use a foreign key approach, merge the tables, or create a separate relationship table? The algorithm says 'choose based on participation and access patterns'—but what does that actually mean for your specific system?
This page examines the major design decisions that arise during mapping, the factors that influence each choice, and frameworks for making decisions that optimize for your specific requirements. Mastering these decisions separates competent database practitioners from experts who design schemas that perform well under real-world conditions.
By the end of this page, you will understand the key design decisions in ER-to-relational mapping, the factors that influence each decision, and systematic approaches for making optimal choices. You'll develop the judgment needed to go beyond mechanical algorithm application.
Categories of Design Decisions
Design decisions during mapping fall into several categories, each with distinct considerations:
Taxonomy of Mapping Decisions:
| Category | Example Decisions | Primary Influencing Factors |
|---|---|---|
| Structural Decisions | Table merging vs. separation, junction table design | Access patterns, query complexity, data volume |
| Key Decisions | Natural vs. surrogate keys, composite key composition | Stability, performance, integration requirements |
| Relationship Representation | FK placement in 1:1, relationship table use | Participation constraints, nullability tolerance |
| Constraint Specification | Referential actions, nullability, check constraints | Business rules, cascade behavior requirements |
| Inheritance Mapping | Single table, multiple tables, or hybrid | Query patterns, sparsity, type discrimination needs |
| Attribute Handling | Derived attribute storage, composite flattening | Computation cost, update frequency, query needs |
The Decision-Making Framework:
For each decision point, apply this systematic framework:
- Identify the Options — What are the valid mapping approaches?
- Enumerate Criteria — What factors matter for this decision?
- Gather Information — What do you know about access patterns, data volumes, business rules?
- Evaluate Trade-offs — How does each option perform against each criterion?
- Make and Document — Choose, record the rationale for future reference
This framework prevents ad-hoc decisions and creates an audit trail for schema evolution.
A critical insight: there's rarely a universally optimal choice. The best decision depends on your specific context—access patterns, data distribution, performance requirements, and maintenance constraints. Two equally skilled designers may make different choices for identical ER diagrams if their usage scenarios differ.
Decision: Natural vs. Surrogate Keys
Perhaps the most debated design decision is whether to use natural keys (derived from data attributes) or surrogate keys (system-generated identifiers). This decision has cascading effects throughout the schema.
Natural Key Characteristics:
Natural keys use attributes that carry business meaning—ISBN for books, SSN for US persons, email addresses, product codes, etc.
Surrogate Key Characteristics:
Surrogate keys are system-generated values with no business meaning—auto-increment integers, UUIDs, sequences.
- •Human-readable — Identifiers carry meaning in queries and reports
- •Self-documenting joins — FK values reveal related entity
- •Integration-friendly — Easier data exchange between systems
- •Duplicate prevention — Natural uniqueness enforced automatically
- •Query simplicity — No lookup needed to understand references
- •Stability — Never need to change regardless of business rules
- •Compact size — Integer keys are small, fast for joins/indexes
- •Uniform structure — All PKs have same type, simplifies framework code
- •Privacy — No sensitive data in relationship columns
- •Simplicity — Always single-column, never composite
Decision Factors:
| Factor | Favor Natural | Favor Surrogate |
|---|---|---|
| Key stability | Attribute will never change | Attribute may change (email, name, code) |
| Key complexity | Simple single attribute | Would require composite key |
| Key size | Reasonably compact | Large string or multi-column composite |
| Data integration | Cross-system data exchange common | Primarily internal use |
| Privacy concerns | Attribute is non-sensitive | Would expose sensitive data in FKs |
| Performance priority | Query readability more important | Join performance critical |
| ORM usage | Limited or no ORM | Heavy ORM use (ORMs prefer surrogates) |
Many production systems use both: surrogate keys as the primary key for FK references and internal operations, plus UNIQUE constraints on natural key attributes for business rule enforcement. This captures most benefits of both approaches.
12345678910111213141516171819202122
-- Hybrid approach: surrogate PK with natural UNIQUE constraintCREATE TABLE PRODUCT ( ProductID INT PRIMARY KEY AUTO_INCREMENT, -- Surrogate ProductSKU VARCHAR(20) NOT NULL UNIQUE, -- Natural (business key) ProductName VARCHAR(100) NOT NULL, Price DECIMAL(10,2)); CREATE TABLE ORDER_ITEM ( ItemID INT PRIMARY KEY AUTO_INCREMENT, OrderID INT NOT NULL, ProductID INT NOT NULL, -- FK uses surrogate (compact, stable) Quantity INT NOT NULL, FOREIGN KEY (ProductID) REFERENCES PRODUCT(ProductID)); -- Business queries can use SKU for human interaction-- SELECT * FROM PRODUCT WHERE ProductSKU = 'ABC-12345'; -- Internal joins use efficient integer keys-- Relationships reference ProductID (4 bytes) not SKU (20 bytes)Decision: 1:1 Relationship Mapping Strategy
1:1 relationships offer three mapping approaches, each with distinct trade-offs. The choice significantly impacts query patterns, nullability, and schema evolution.
The Three Approaches Revisited:
Description: Add a foreign key column to one entity's table referencing the other. The FK column has a UNIQUE constraint to enforce the 1:1 cardinality.
When to Use:
- One entity has total participation, the other partial
- Entities are frequently accessed independently
- Future schema changes may affect one entity but not the other
Where to Place the FK:
- Place FK on the side with total participation (NOT NULL FK)
- If both partial, place on the side with fewer rows (reduces NULL storage)
- If both total, either side works—consider access patterns
Trade-offs:
- ✅ Clear entity separation
- ✅ Easy to evolve independently
- ❌ Requires join for combined access
- ❌ One side may have nullable FK
12345678910
-- EMPLOYEE manages DEPARTMENT (1:1)-- FK in DEPARTMENT (total participation - every dept has manager) CREATE TABLE DEPARTMENT ( DeptID INT PRIMARY KEY, DeptName VARCHAR(50) NOT NULL, ManagerSSN CHAR(11) NOT NULL UNIQUE, -- 1:1 enforced FOREIGN KEY (ManagerSSN) REFERENCES EMPLOYEE(SSN));Default to the Foreign Key Approach—it's the most flexible. Only choose Merged Tables when you're confident the entities are permanently coupled. Use Relationship Tables when both participations are partial or you need to track relationship history.
Decision: Specialization Mapping Strategy
Specialization/Generalization hierarchies (supertype/subtype relationships) present one of the most complex mapping decisions. The relational model lacks native inheritance, so we must simulate it through table structures.
The Three Strategies:
| Strategy | Description | Tables Created |
|---|---|---|
| Single Table (STI) | One table for entire hierarchy with type discriminator column | 1 table with all attributes from supertype + all subtypes |
| Class Table (CTI) | Separate table for each type in hierarchy | 1 table per type, subtypes reference supertype via FK |
| Concrete Table (CTI) | Separate table per concrete subtype only | 1 table per concrete subtype, each has all inherited attributes |
Detailed Strategy Analysis:
Single Table Inheritance (STI):
CREATE TABLE PERSON (
PersonID INT PRIMARY KEY,
PersonType VARCHAR(20) NOT NULL,
-- Common attributes
Name VARCHAR(100) NOT NULL,
Address VARCHAR(200),
-- Student-specific (NULL for non-students)
StudentID VARCHAR(20),
GPA DECIMAL(3,2),
-- Employee-specific (NULL for non-employees)
EmployeeID VARCHAR(20),
Salary DECIMAL(10,2)
);
Pros:
- Simple—single table to query
- No joins for complete entity
- Easy polymorphic queries
Cons:
- Many NULL values (sparse table)
- All subtype constraints via CHECK clauses
- Schema changes affect entire table
- May hit column limits
Class Table Inheritance (CTI):
CREATE TABLE PERSON (
PersonID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Address VARCHAR(200)
);
CREATE TABLE STUDENT (
PersonID INT PRIMARY KEY,
StudentID VARCHAR(20) NOT NULL,
GPA DECIMAL(3,2),
FOREIGN KEY (PersonID)
REFERENCES PERSON(PersonID)
);
CREATE TABLE EMPLOYEE (
PersonID INT PRIMARY KEY,
EmployeeID VARCHAR(20) NOT NULL,
Salary DECIMAL(10,2),
FOREIGN KEY (PersonID)
REFERENCES PERSON(PersonID)
);
Pros:
- No NULL waste
- Subtype constraints easy to enforce
- Clean separation of concerns
Cons:
- Joins required for complete entity
- Polymorphic queries complex
- Multiple inserts/updates
Concrete Table Inheritance:
-- No PERSON table - attributes duplicated
CREATE TABLE STUDENT (
PersonID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL, -- Duplicated
Address VARCHAR(200), -- Duplicated
StudentID VARCHAR(20) NOT NULL,
GPA DECIMAL(3,2)
);
CREATE TABLE EMPLOYEE (
PersonID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL, -- Duplicated
Address VARCHAR(200), -- Duplicated
EmployeeID VARCHAR(20) NOT NULL,
Salary DECIMAL(10,2)
);
Use When: Subtypes are disjoint and supertype is abstract (never instantiated directly).
Pros: No joins; each subtype is self-contained
Cons: No unified view; duplicate columns; changes to inherited attributes require multi-table updates
| Factor | Single Table | Class Table | Concrete Table |
|---|---|---|---|
| Few subtypes with similar attributes | ✅ Best | ⚠️ Okay | ❌ Avoid |
| Many diverse subtypes | ❌ Avoid (too sparse) | ✅ Best | ⚠️ Consider |
| Frequent polymorphic queries | ✅ Best | ⚠️ Complex | ❌ Avoid |
| Subtype-specific queries dominate | ⚠️ Okay | ✅ Best | ✅ Best |
| Overlapping specialization | ✅ Best | ✅ Works (multi-FK) | ❌ Avoid |
| Strong subtype constraints | ❌ Hard to enforce | ✅ Best | ✅ Best |
| Performance-critical reads | ✅ No joins | ❌ Requires joins | ✅ No joins |
Decision: Referential Actions
When defining foreign key constraints, you must specify what happens when the referenced row is deleted or updated. This decision directly translates business rules into database behavior.
Referential Action Options:
| Action | ON DELETE Behavior | ON UPDATE Behavior | Use Case |
|---|---|---|---|
| CASCADE | Delete all referencing rows | Update FK values to match | Dependent entities (OrderItems when Order deleted) |
| RESTRICT | Block deletion if references exist | Block update if references exist | Protect data from accidental loss |
| NO ACTION | Same as RESTRICT (standard SQL) | Same as RESTRICT | Default if not specified |
| SET NULL | Set FK to NULL | Set FK to NULL | Optional relationships (Employee dept when dept deleted) |
| SET DEFAULT | Set FK to default value | Set FK to default value | When a default entity exists ("Uncategorized") |
Decision Framework:
For each foreign key, ask:
-
Does the referencing entity make sense without the referenced entity?
- No → CASCADE or RESTRICT
- Yes → SET NULL or SET DEFAULT
-
Should deletion be automatic or require explicit handling?
- Automatic cleanup okay → CASCADE
- Require explicit decision → RESTRICT
-
Can the FK column accept NULL?
- Yes → SET NULL is option
- No → SET NULL not viable
-
Is there a sensible default entity?
- Yes → SET DEFAULT is option
- No → Cannot use SET DEFAULT
Referential Action Decisions for an E-Commerce System
Different relationships require different referential actions
1. **ORDER → ORDER_ITEM** (1:N): Order contains items
2. **CUSTOMER → ORDER** (1:N): Customer places orders
3. **PRODUCT → ORDER_ITEM** (1:N): Items reference products
4. **EMPLOYEE → ORDER** (1:N): Employee processes order```sql
-- ORDER_ITEM.OrderID → CASCADE
-- Items meaningless without order
FOREIGN KEY (OrderID) REFERENCES ORDER(OrderID)
ON DELETE CASCADE
ON UPDATE CASCADE
-- ORDER.CustomerID → RESTRICT
-- Must explicitly handle customer with order history
FOREIGN KEY (CustomerID) REFERENCES CUSTOMER(CustomerID)
ON DELETE RESTRICT
ON UPDATE CASCADE
-- ORDER_ITEM.ProductID → RESTRICT
-- Cannot delete product referenced in orders
FOREIGN KEY (ProductID) REFERENCES PRODUCT(ProductID)
ON DELETE RESTRICT
ON UPDATE CASCADE
-- ORDER.ProcessedBy → SET NULL
-- Order exists even if employee leaves
FOREIGN KEY (ProcessedBy) REFERENCES EMPLOYEE(EmployeeID)
ON DELETE SET NULL
ON UPDATE CASCADE
```Be careful with CASCADE on tables with many relationships. A single DELETE can trigger cascading deletions across multiple tables, potentially removing more data than intended. Always map out cascade chains before deployment and consider RESTRICT with explicit application logic for critical data.
Decision: Nullability and Optional Data
NULL is one of the most misunderstood aspects of relational databases. Deciding when to allow NULLs has significant implications for query behavior, constraint enforcement, and storage efficiency.
What NULL Represents:
NULL can mean:
- Value is unknown (we don't know the customer's middle name)
- Value doesn't apply (a non-US address has no State)
- Value was not provided (optional field left blank)
- Value doesn't exist yet (ship date for unshipped order)
This semantic ambiguity is why NULL requires careful handling.
Nullability Decision Matrix:
| Situation | NULL? | Rationale |
|---|---|---|
| Primary key column | NEVER | PKs must uniquely identify; NULL cannot equal NULL |
| Foreign key with total participation | No | Relationship is mandatory—every row must reference |
| Foreign key with partial participation | Yes | Some rows may not have the relationship |
| Attribute that must always be provided | No | Business rule: this data is required |
| Attribute that may be unknown/optional | Yes | Legitimate cases where data isn't available |
| Computed/derived column | Depends | If derivation can fail, allow NULL; otherwise NOT NULL |
| Boolean flags | Avoid | Use NOT NULL with default; NULL boolean is confusing |
NULL Handling Strategies:
-
Explicit DEFAULT Values: Instead of NULL, use a sentinel value when semantically appropriate:
-- Instead of NULL for unknown Status VARCHAR(20) NOT NULL DEFAULT 'UNKNOWN' -
Separate Optional Tables: For attributes that are optional for many rows, consider a separate table:
-- Instead of nullable columns in EMPLOYEE CREATE TABLE EMPLOYEE_MEDICAL_INFO ( EmployeeSSN CHAR(11) PRIMARY KEY, BloodType CHAR(3), Allergies TEXT, FOREIGN KEY (EmployeeSSN) REFERENCES EMPLOYEE(SSN) ); -- Only rows that have medical info are stored -
Application-Level Handling: Accept NULLs in database but handle at application layer with validation logic.
Query Implications:
NULLs complicate queries due to three-valued logic:
NULL = NULLevaluates to NULL (unknown), not TRUENULL <> 'value'evaluates to NULL, not TRUE- Aggregates like COUNT(*) include NULLs; COUNT(column) excludes them
- WHERE clauses with NULLable columns need COALESCE or IS NULL handling
While NULLs are sometimes necessary, prefer NOT NULL with defaults when semantically correct. NOT NULL columns enable better query optimization, avoid NULL-handling bugs, and make constraints simpler to express.
Decision: Documentation Depth
A often-overlooked design decision is how thoroughly to document mapping decisions. Future maintainers—including your future self—will benefit from understanding why certain choices were made.
What to Document:
- •Entity-Table Mapping Matrix — Which ER entity became which table(s)
- •Relationship Mapping Decisions — Which approach was chosen and why
- •Key Selection Rationale — Why specific keys were chosen (natural vs. surrogate)
- •Constraint Justifications — Business rules behind each constraint
- •Specialization Strategy — Which inheritance mapping was used
- •Rejected Alternatives — Approaches considered but not chosen, with reasons
- •Assumptions Made — Any assumptions about data volume, access patterns, etc.
- •Known Limitations — Constraints that cannot be enforced in the schema
Documentation Formats:
-
Inline in DDL:
-- FK on DEPARTMENT: Total participation (every dept has manager) -- UNIQUE enforces 1:1 (each employee manages at most one dept) ManagerSSN CHAR(11) NOT NULL UNIQUE, -
Data Dictionary: Formal document mapping columns to business definitions:
| Table | Column | Description | Source ER Element | Constraints |
|---|---|---|---|---|
| DEPT | ManagerSSN | SSN of dept manager | MANAGES relationship | FK, NOT NULL, UNIQUE |
- Design Decision Log:
Narrative document explaining each decision point:
Decision: 1:1 MANAGES Relationship
Chose Foreign Key approach with FK in DEPARTMENT because:
- Department has total participation (every dept requires manager)
- Manager relationship is accessed when querying departments
- Rejected merged table: entities have distinct lifecycles
KEEP LEARNING
Keep learning for free.
Read the complete lesson, save your notes and pick up where you left off with a free account. No card needed.