← Back to quizzesFree quiz

Relational Databases and Coding Fundamentals

Relational databases are the backbone of modern information systems. They allow us to model real‑world entities, define relationships, enforce data integrity, and manage concurrent access.…

10 questions~5 min
Relational Databases and Coding Fundamentals — Qwi
0 / 10
Score: 0%
1

In a dealership scenario, can one Customer (Agent) be linked to multiple Sales (Events), and what business concept does this represent?

2

Why is the transaction "Date" stored in the Event table rather than the Agent table in a REA model?

3

Which table acts as the bridge between the Stock (Resource) and the Salesman (Agent) in a typical REA schema?

4

If a table lists "Customer Name" and "Address" for every invoice, which normal form is being violated?

5

Why is License_Plate a better primary key than Truck_Color for the Lucky Cement Trucks table?

6

When a City row is deleted while cement bags still reference it, what integrity violation occurs in the database?

7

How does a foreign key connect a Sales Invoice to a specific Warehouse in an RDBMS?

8

If two customers simultaneously attempt to buy the last 100 bags of cement, which concurrency control mechanism typically resolves the conflict?

9

Why is the "Product Code" field usually mandatory in a software entry screen for Lucky Cement?

10

In the data hierarchy, which ordering correctly lists components from smallest to largest?

Understanding Relational Databases and Core Coding Concepts

Relational databases are the backbone of modern information systems. They allow us to model real‑world entities, define relationships, enforce data integrity, and manage concurrent access. This course breaks down the essential concepts tested in a typical quiz on relational databases, using a dealership and cement‑industry scenario to illustrate each point.

1. One‑to‑Many Relationships in Business Modeling

In a dealership context, a Customer (Agent) can be linked to multiple Sales (Events). This reflects a classic one‑to‑many relationship where one record in the Customer table relates to many records in the Sales table.

  • Key idea: The foreign key customer_id resides in the Sales table, pointing back to the primary key of Customer.
  • Business impact: Enables tracking of every purchase a customer makes, supporting analytics such as total spend, purchase frequency, and loyalty programs.
  • Contrast: A one‑to‑one relationship would limit each customer to a single sale, which rarely matches real business needs.

2. The REA Model: Where Does the Transaction Date Belong?

The REA (Resources‑Events‑Agents) model separates entities (agents and resources) from transactions (events). The date of a transaction is an attribute of the Event table, not the Agent table, because:

  • Dates describe when an event occurred, not who performed it.
  • Storing the date with the event keeps the schema normalized and avoids redundant data.
  • It simplifies queries that need to filter events by time periods (e.g., monthly sales reports).

3. Bridging Resources and Agents: The Role of the Sales (Event) Table

In a typical REA schema, the Sales (Event) table acts as the bridge between Stock (Resource) and Salesman (Agent). This table contains foreign keys to both the resource and the agent, establishing a many‑to‑many relationship that is resolved through the event record.

  • Each sale records which stock item was sold and which salesperson facilitated the transaction.
  • Without this bridge, you would need a separate mapping table, which adds unnecessary complexity.

4. Normalization Basics: Detecting First Normal Form Violations

Normalization ensures that tables store data efficiently and without redundancy. When an Invoice table lists both "Customer Name" and "Address" for every row, it violates First Normal Form (1NF) because:

  • Repeating groups (name and address) are stored alongside transactional data, leading to duplicated information.
  • Any change to a customer's address would require updates to multiple invoice rows, increasing the risk of inconsistency.
  • Proper design moves customer details to a separate Customer table and references it via a foreign key.

5. Choosing Effective Primary Keys

Primary keys must uniquely identify each row. In the Lucky Cement Trucks table, License_Plate is a superior primary key compared to Truck_Color because:

  • License plates are legally required to be unique for each vehicle, guaranteeing distinctness.
  • Colors are not unique; many trucks can share the same color, leading to ambiguous identification.
  • A stable, non‑changing attribute (e.g., VIN) is ideal, but when using license plates, ensure they are updated only when legally required.

6. Maintaining Referential Integrity: Deleting Referenced Rows

When a City row is deleted while Inventory rows still reference it, the database raises a referential integrity error. This occurs because:

  • The foreign key in Inventory points to the now‑nonexistent City primary key.
  • Without cascading rules (ON DELETE CASCADE), the database prevents orphaned records that would break data consistency.
  • Solutions include using cascading deletes, setting the foreign key to NULL, or preventing the delete until dependent rows are handled.

7. How Foreign Keys Connect Tables

A foreign key creates a logical link between tables. For a Sales Invoice to reference a specific Warehouse:

  • The invoice row stores the warehouse_id, which is the primary key of the Warehouse table.
  • This single column establishes the relationship, allowing queries like SELECT * FROM Invoice JOIN Warehouse ON Invoice.warehouse_id = Warehouse.id.
  • It also enforces that every invoice must reference a valid warehouse, preserving data integrity.

8. Concurrency Control: Resolving Simultaneous Purchases

When two customers attempt to buy the last 100 bags of cement at the same time, the database typically employs row‑level locking. The mechanism works as follows:

  • The first transaction that acquires a lock on the inventory row proceeds, decrementing the quantity.
  • The second transaction must wait until the lock is released, then re‑checks the available quantity.
  • If the quantity is insufficient after the first transaction, the second transaction aborts or rolls back, preventing negative inventory.

Other strategies, such as optimistic concurrency, can be used in high‑throughput environments, but row‑level locking remains the most common default in relational DBMSs.

9. Summary of Key Concepts

By mastering these foundational ideas, developers and database designers can build robust, scalable systems that accurately reflect business processes.

  • One‑to‑many relationships model customers and multiple sales.
  • In the REA model, event attributes like dates belong to the Event table.
  • The Sales table serves as the bridge between resources and agents.
  • Violating First Normal Form leads to redundancy; always separate entities from transactions.
  • Choose primary keys that guarantee uniqueness, such as license plates over colors.
  • Referential integrity protects against orphaned records when deleting referenced rows.
  • Foreign keys store the primary key of the related table, establishing a logical link.
  • Row‑level locking resolves concurrency conflicts, ensuring accurate inventory counts.

Implementing these principles not only improves data quality but also enhances query performance and application reliability. For developers seeking to deepen their expertise, further study of advanced normalization (2NF, 3NF, BCNF), indexing strategies, and transaction isolation levels is recommended.