From Role–Actor Cast Lists to Complete Data Models: Relational Database Normalization and Query Practices

    Using a role–actor mapping as a running example, this article explains how to identify entities, design normalized relational tables, and write queries for real applications. It covers role, actor, and junction table schemas; update, insert, and delete anomalies; basic joins, aggregation, time-based filtering, and index-based optimization; and the trade-off between normalization and denormalization. It also shows how the same modeling approach extends to books/authors, products/tags, RBAC, and location-time associations.

    1. From a Cast List to a Data Model: Reframing the Problem Domain

    A simple role-to-actor cast list actually implies a classic data modeling scenario: two entities—Role and Actor—have an explicit mapping relationship. That mapping can be one-to-one, one-to-many, or many-to-many. In the relational database world, the first step is always to clarify the entities and the business rules between them, and then map those rules to table structures and constraints. This is not only physical storage design; it is a rigorous abstraction of business logic.

    Consider casting information for Notre-Dame de Paris:

    • Roles: Quasimodo, Claude Frollo, Clopin Trouillefou, Pierre Gringoire, Esmeralda
    • Actors: Anthony Hopkins, Derek Jacobi, David Suchet, Gerry Sundquist, Lesley-Anne Down

    There is a natural role–actor association here. If an actor plays only one role in a production and a role is played by only one actor, the relationship is one-to-one. In real scenarios, however, an actor may play multiple roles, and a role may correspond to multiple actors, such as in animation voice work or rotating stage performances. A more reasonable modeling approach is therefore to treat the relationship as many-to-many and decouple it with a junction table. This is an extremely common pattern in relational database design and a necessary step toward normalized design.

    2. Entity Division and Table Structure Design

    The core of relational database design is entity identification and attribute definition. Based on the mapping above, we can break the model into three core tables.

    2.1 Role Table

    The role table stores the inherent attributes of a role. The role identifier serves as the primary key, while the role name, type, description, and similar fields are ordinary attributes.

    1. CREATE TABLE role (
    2. role_id INT PRIMARY KEY,
    3. role_name VARCHAR(50) NOT NULL,
    4. role_type VARCHAR(20),
    5. description TEXT
    6. );

    2.2 Actor Table

    The actor table stores basic actor information. Each actor has a globally unique actor number, and the table records business attributes such as name, nationality, birth date, and debut year. This layer looks simple, but controlling attribute granularity directly affects the complexity of later queries. For example, should birth year and birth date be split into two fields? Should age be stored redundantly? These choices need to be weighed against the specific business scenario.

    1. CREATE TABLE actor (
    2. actor_id INT PRIMARY KEY,
    3. actor_name VARCHAR(50) NOT NULL,
    4. nationality VARCHAR(30),
    5. birth_date DATE,
    6. debut_year INT
    7. );

    2.3 Junction Table

    A many-to-many relationship must be expressed through an independent junction table. This table references the primary key of the role table and the primary key of the actor table as composite foreign keys, and it can be extended with additional attributes as needed, such as appearance order, remarks about the performance, or weight of the role in the production. A composite primary key prevents duplicate associations and ensures data consistency.

    1. CREATE TABLE role_actor_mapping (
    2. role_id INT NOT NULL,
    3. actor_id INT NOT NULL,
    4. appearance_order INT,
    5. remarks VARCHAR(100),
    6. PRIMARY KEY (role_id, actor_id),
    7. FOREIGN KEY (role_id) REFERENCES role(role_id),
    8. FOREIGN KEY (actor_id) REFERENCES actor(actor_id)
    9. );

    The core value of this design is that role information and actor information are maintained independently without interfering with each other. When an actor’s birth date needs to be updated, only one row in the actor table is updated. When a role description needs to be added, only the role table is involved. The junction table avoids duplicate data storage and eliminates update and delete anomalies caused by data redundancy at the root. This is a direct reflection of the requirements of second normal form and third normal form.

    3. The Deeper Meaning of Normalized Design

    Design standards are often ignored until real maintenance scenarios appear. Take the role–actor table as an example. If the model is not split and roles and actors are stacked directly into one wide table, several typical problems arise:

    • Update anomaly: An actor appears in multiple productions. If the actor’s name or basic information changes, multiple rows in the wide table must be updated synchronously. Missing any row causes data inconsistency.
    • Insert anomaly: A new actor has not yet been assigned any role, but because the table’s primary key is tightly coupled with roles, the actor’s information cannot be inserted.
    • Delete anomaly: Deleting a role also deletes all information about the actor, causing loss of facts.

    Normalized design completely avoids these problems. Roles and actors become independent entity sets, and the cross table carries only the association between them. After following normalization, the database structure is more stable and more flexible in responding to business rules. For example, it allows a role to have no actor yet, and it allows an actor to be attached to multiple unassigned roles, which is very useful during data initialization.

    4. Query Practice: From Simple Lookups to Complex Analysis

    Table structure design is only the first step in database application. Query capability is what truly empowers the business. The following examples use the role–actor scenario to show the progression from basic queries to more complex analysis.

    4.1 Basic Join Query

    To retrieve the complete list of all roles and their corresponding actors, a two-table join is enough:

    1. SELECT
    2. r.role_name,
    3. a.actor_name
    4. FROM role r
    5. JOIN role_actor_mapping m ON r.role_id = m.role_id
    6. JOIN actor a ON a.actor_id = m.actor_id
    7. ORDER BY m.appearance_order;

    The JOIN operation here reflects the core idea of relational databases: recombining distributed data through foreign key associations. Index usage directly determines join query performance. If foreign key columns lack indexes, large data volumes can produce many nested loop scans and seriously affect query response time.

    4.2 Aggregation Analysis

    To count the number of roles each actor has played, use GROUP BY for grouped aggregation:

    1. SELECT
    2. a.actor_name,
    3. COUNT(m.role_id) AS role_count
    4. FROM actor a
    5. LEFT JOIN role_actor_mapping m ON a.actor_id = m.actor_id
    6. GROUP BY a.actor_id, a.actor_name
    7. HAVING COUNT(m.role_id) >= 1;

    Here LEFT JOIN ensures that actors with no assigned roles also appear in the result set with a role count of 0, while the HAVING clause filters the aggregated results. This is one of the most common query patterns in OLTP and lightweight OLAP scenarios.

    4.3 Filtering Based on Time Attributes

    Extend the scenario further: if the actor table records each actor’s birth date, we need to find actors who were no older than 30 when they played a role. This requires obtaining the performance year associated with the role through the junction table and then calculating it with the birth_date in the actor table. This involves a combination of cross-table calculation and conditional filtering:

    1. SELECT
    2. r.role_name,
    3. a.actor_name,
    4. YEAR(m.performance_year) - YEAR(a.birth_date) AS age_at_performance
    5. FROM role_actor_mapping m
    6. JOIN role r ON m.role_id = r.role_id
    7. JOIN actor a ON m.actor_id = a.actor_id
    8. WHERE (YEAR(m.performance_year) - YEAR(a.birth_date)) < 30;

    This case demonstrates how to dynamically construct a calculated field in a join query and reference the calculation logic in a filter condition. It also implies that the junction table needs to store an attribute such as performance year.

    4.4 Query Selectivity Optimization

    As table data grows, query performance optimization gradually becomes a focus for developers. For role queries, the most frequent search condition may be an exact lookup by role name. In this case, creating an index on the role_name column of the role table greatly improves equality query efficiency. For fuzzy matching requirements, such as searching for role names containing a keyword, balance index utilization against the overhead of LIKE pattern matching.

    1. CREATE INDEX idx_role_name ON role(role_name);

    In addition, creating a composite index on role_id and actor_id in the role_actor_mapping table can accelerate joins between the two tables and avoid full table scans that degrade query performance. For statistical scenarios with very large tables and fixed aggregation conditions, consider materialized views or periodically generated summary tables to trade space for time and achieve millisecond-level response.

    5. Normalization and Denormalization: Necessary Engineering Trade-offs

    Strictly following normalization often leads to a large number of table joins, and too many joins inevitably reduce query speed. This is where denormalization comes in: redundantly storing some frequently accessed fields in core business tables to reduce the number of joins.

    For example, if the business frequently needs to display a direct list of actor names and role names and almost never updates them independently, role names and actor names can be redundantly stored in the junction table. In that case, even without a multi-table JOIN, a single table scan can complete the query and significantly optimize I/O cost. The trade-off is that redundant fields must be kept consistent during updates, usually through explicit transaction control or unified maintenance in application code.

    Denormalization is not a rejection of normalization. It is a trade-off between read performance and write consistency. A good data model designer needs to estimate future read/write ratios and performance goals at the beginning of modeling, and then selectively break normalization rather than blindly following every rule.

    6. Extended Thinking: Beyond the Role–Actor Table

    The thinking based on this simple pair of entities—role and actor—can be transferred to a broader range of business scenarios:

    • Books and authors: A book can have multiple authors, and an author can write multiple books. The junction table can additionally record contribution percentage or byline order.
    • Products and tags: Products and tags have a many-to-many relationship. The tag system design directly affects the recall and precision of a recommendation system.
    • Users and permissions: In the RBAC model, users, roles, and permissions each have many-to-many relationships. Implementing fine-grained authorization management through junction tables is the core skeleton of almost every backend system.
    • Roles in geographic space: If each role appears in different locations in a novel, such as Notre-Dame and Place de Grève, the model can be extended into a three-dimensional role–location–time association, forming a more complex but more analytically valuable star model.

    The essence of these scenarios is the same: abstract relationships in the real world into a combination of entities, attributes, and associations, convert them into table structures in a standardized way, and then use query languages to reconstruct the information views required by the business.

    7. Conclusion

    Starting from a simple role–actor cast list, we have walked through the full process of requirements analysis, entity modeling, table structure design, normalization constraints, query writing, and performance optimization. This process is a true microcosm of relational database engineering practice: it is not only about whether a CREATE TABLE statement can execute, but also about whether the design can support business evolution, whether queries can meet timeliness requirements, and whether data can remain consistent and trustworthy over years of maintenance.

    No matter how technology stacks change or how NoSQL products evolve, the relational model remains the preferred foundation for most business systems because of its solid mathematical basis and mature transaction mechanisms. Mastering a design methodology built on primary and foreign keys as the skeleton, normalization as the guideline, and indexes as accelerators is a key step for every backend developer moving from writing code to designing systems.