A relational database stores data in tables made of rows and columns. Each table represents an entity, and relationships between tables are made using keys.
Click to reveal answer
beginner
What is a primary key in a relational database?
A primary key is a column or set of columns that uniquely identifies each row in a table. It ensures no two rows have the same key value.
Click to reveal answer
intermediate
Explain the concept of foreign key.
A foreign key is a column in one table that refers to the primary key in another table. It creates a link between the two tables to maintain data consistency.
Click to reveal answer
intermediate
What is normalization in relational databases?
Normalization is the process of organizing data to reduce duplication and improve data integrity by dividing tables and defining relationships.
Click to reveal answer
beginner
What does SQL stand for and what is its role?
SQL stands for Structured Query Language. It is used to communicate with and manage data in relational databases by writing queries.
Click to reveal answer
Which of the following uniquely identifies a row in a table?
APrimary key
BForeign key
CIndex
DColumn name
✗ Incorrect
The primary key uniquely identifies each row in a table.
What does a foreign key do?
ASorts data alphabetically
BCreates a new table
CDeletes duplicate rows
DLinks one table to another
✗ Incorrect
A foreign key links one table to another by referring to the primary key.
Normalization helps to:
AReduce data duplication
BIncrease data duplication
CMake data harder to access
DStore data in one big table
✗ Incorrect
Normalization organizes data to reduce duplication and improve integrity.
Which language is used to query relational databases?
AHTML
BCSS
CSQL
DJavaScript
✗ Incorrect
SQL is the language used to query and manage relational databases.
In a table, columns represent:
AIndividual records
BAttributes or fields
CDatabase names
DUser permissions
✗ Incorrect
Columns represent attributes or fields describing data in each row.
Describe the role of primary and foreign keys in relational databases.
Think about how tables connect and keep data unique.
You got /3 concepts.
Explain why normalization is important in database design.
Consider how data is stored efficiently and cleanly.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of a primary key in a relational database table?
easy
A. To speed up database backups
B. To store large text data
C. To link two tables together
D. To uniquely identify each record in the table
Solution
Step 1: Understand the role of primary keys
A primary key is a column or set of columns that uniquely identifies each row in a table.
Step 2: Compare options with the definition
Only To uniquely identify each record in the table describes this unique identification role correctly.
Final Answer:
To uniquely identify each record in the table -> Option D
Quick Check:
Primary key = unique record ID [OK]
Hint: Primary key means unique ID for each row [OK]
Common Mistakes:
Confusing primary key with foreign key
Thinking primary key stores large data
Assuming primary key speeds backups
2. Which of the following is the correct syntax to declare a primary key on the column id in a MySQL table?
easy
A. PRIMARY KEY (id);
B. KEY PRIMARY id;
C. PRIMARY KEY id;
D. PRIMARY id KEY;
Solution
Step 1: Recall MySQL primary key syntax
In MySQL, the primary key is declared using PRIMARY KEY (column_name).
Step 2: Match syntax with options
PRIMARY KEY (id); matches the correct syntax with parentheses around the column name.
Final Answer:
PRIMARY KEY (id); -> Option A
Quick Check:
Primary key syntax uses parentheses [OK]
Hint: Primary key syntax uses parentheses around column [OK]
Common Mistakes:
Omitting parentheses around column name
Swapping order of keywords
Using incorrect keywords like KEY PRIMARY
3. Given two tables: Customers(id, name) and Orders(order_id, customer_id), which SQL query correctly retrieves all orders with the customer names?
medium
A. SELECT Orders.order_id, Customers.name FROM Orders JOIN Customers ON Orders.id = Customers.customer_id;
B. SELECT Orders.order_id, Customers.name FROM Orders JOIN Customers ON Orders.customer_id = Customers.id;
C. SELECT order_id, name FROM Orders, Customers WHERE Orders.id = Customers.id;
D. SELECT order_id, name FROM Orders LEFT JOIN Customers ON Orders.customer_id = Customers.order_id;
Solution
Step 1: Identify the correct join condition
The foreign key customer_id in Orders links to id in Customers.
Step 2: Check each option's join condition
SELECT Orders.order_id, Customers.name FROM Orders JOIN Customers ON Orders.customer_id = Customers.id; correctly joins on Orders.customer_id = Customers.id. Others use wrong columns or join types.
Final Answer:
SELECT Orders.order_id, Customers.name FROM Orders JOIN Customers ON Orders.customer_id = Customers.id; -> Option B
Quick Check:
Join on foreign key = primary key [OK]
Hint: Join tables on foreign key = primary key [OK]
Common Mistakes:
Swapping join columns incorrectly
Using WHERE instead of JOIN condition properly
Mixing up LEFT JOIN with INNER JOIN
4. You wrote this SQL to create a foreign key: FOREIGN KEY (customer_id) REFERENCES Customers(customer_id). But it gives an error. What is the likely cause?
medium
A. You must declare foreign keys before primary keys
B. Foreign keys cannot reference columns in the same table
C. The referenced column customer_id does not exist or is not a primary key in Customers
D. Foreign keys must reference columns named 'id' only
Solution
Step 1: Understand foreign key requirements
A foreign key must reference a column that exists and is a primary or unique key in the referenced table.
Step 2: Analyze the error cause
If Customers has no customer_id column or it is not a key, the foreign key declaration fails.
Final Answer:
The referenced column customer_id does not exist or is not a primary key in Customers -> Option C
Quick Check:
Foreign key must reference existing primary key [OK]
Hint: Foreign key must reference existing primary key column [OK]
Common Mistakes:
Referencing non-existent columns
Assuming foreign keys must reference 'id' column
Incorrect order of key declarations
5. You have two tables: Employees(emp_id, name) and Departments(dept_id, dept_name, manager_id). The manager_id in Departments references emp_id in Employees. Which of these statements is TRUE about this relationship?
hard
A. An employee can manage multiple departments, but a department can have only one manager
B. Each department must have exactly one manager who is an employee
C. A department can have multiple managers if multiple employees share the same emp_id
D. The manager_id column in Departments can be NULL only if emp_id is NULL in Employees
Solution
Step 1: Understand foreign key relationship
The manager_id in Departments points to emp_id in Employees, linking each department to one employee as manager.
Step 2: Analyze relationship cardinality
One department has one manager, but an employee can manage many departments (one-to-many).
Step 3: Evaluate options
An employee can manage multiple departments, but a department can have only one manager correctly states this one-to-many relationship. Each department must have exactly one manager who is an employee is wrong because departments can have one manager, but not necessarily exactly one if NULL allowed. A department can have multiple managers if multiple employees share the same emp_id is wrong because emp_id is unique. The manager_id column in Departments can be NULL only if emp_id is NULL in Employees is incorrect because NULL in manager_id is independent of emp_id NULL.
Final Answer:
An employee can manage multiple departments, but a department can have only one manager -> Option A
Quick Check:
One-to-many foreign key = An employee can manage multiple departments, but a department can have only one manager [OK]
Hint: Foreign key one-to-many means one employee, many departments [OK]
Common Mistakes:
Assuming multiple managers per department
Confusing NULL constraints
Thinking emp_id can be duplicated
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.