Consider an ER diagram with two entities: Author and Book. Each author can write many books, but each book has only one author.
How should this relationship be represented in the relational tables?
Think about which entity can have multiple related records.
In a one-to-many relationship, the table on the 'many' side (Book) gets a foreign key referencing the 'one' side (Author).
Given an ER diagram with entities Student and Course having a many-to-many relationship, which table structure correctly represents this in SQL?
Many-to-many relationships require an extra table to connect the two entities.
Many-to-many relationships are implemented using a join table that holds foreign keys to both related tables.
A weak entity Dependent depends on Employee with a partial key dependent_name. Which SQL table definition correctly represents this weak entity?
CREATE TABLE Dependent ( employee_id INT, dependent_name VARCHAR(50), birth_date DATE, PRIMARY KEY (employee_id, dependent_name), FOREIGN KEY (employee_id) REFERENCES Employee(employee_id) );
Weak entities need the owner's key plus their partial key as primary key.
Weak entities use a composite primary key combining the owner's key and their own partial key, with a foreign key referencing the owner.
An ER diagram has a superclass Vehicle and subclasses Car and Truck. Which table design optimizes storage and query performance?
Think about normalization and avoiding NULLs.
Using separate tables for subclasses referencing the superclass avoids NULLs and keeps data organized, improving performance.
Given an ER diagram with entities Order and Customer where each order belongs to one customer, the following SQL tables are created:
CREATE TABLE Customer ( customer_id INT PRIMARY KEY, name VARCHAR(100) ); CREATE TABLE `Order` ( order_id INT PRIMARY KEY, order_date DATE, customer_id INT, FOREIGN KEY (order_id) REFERENCES Customer(customer_id) );
What is the error in this design?
Check which column should reference which in the foreign key.
The foreign key in Order should be on customer_id referencing Customer(customer_id), not on order_id.