Draw a diagram of a simple relational database for a library system. Include two tables: Books and Authors. Show the columns for each table and the relationship between them using primary and foreign keys.
Relational database basics in Intro to Computing - Draw & Build Visually
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Draw This - beginner
Grading Criteria
Solution
+----------------+ +----------------+
| Authors | | Books |
+----------------+ +----------------+
| AuthorID (PK) |<----->| AuthorID (FK) |
| Name | | BookID (PK) |
+----------------+ | Title |
+----------------+This diagram shows two tables: Authors and Books.
The Authors table has AuthorID as the primary key, which uniquely identifies each author, and a Name column for the author's name.
The Books table has BookID as its primary key, a Title column for the book's name, and AuthorID as a foreign key linking each book to its author.
The arrow shows the relationship: each book is linked to one author by matching AuthorID values.
This setup helps organize data so you can find all books by an author or find the author of a book easily.
Variations - 2 Challenges
[intermediate] Draw a relational database diagram for a student enrollment system with three tables: Students, Courses, and Enrollments. Show primary keys, foreign keys, and relationships.
[advanced] Draw a relational database diagram for an online store with tables: Customers, Orders, Products, and OrderDetails. Include primary keys, foreign keys, and relationships.
Practice
1. What is the main purpose of a relational database?
easy
Solution
Step 1: Understand the structure of relational databases
Relational databases store data in tables made of rows and columns, similar to a spreadsheet.Step 2: Compare options with this structure
Only 'To organize data into tables with rows and columns' matches the core purpose of relational databases.Final Answer:
To organize data into tables with rows and columns -> Option CQuick Check:
Relational database = tables with rows and columns [OK]
Hint: Think of data like a spreadsheet with rows and columns [OK]
Common Mistakes:
- Confusing databases with file storage
- Thinking databases create graphics
- Believing databases run programs
2. Which SQL command is used to add new data into a table?
easy
Solution
Step 1: Recall SQL commands and their purposes
SELECT retrieves data, CREATE makes tables, DELETE removes data, and INSERT adds new data.Step 2: Match the command to adding data
INSERT is the command used to add new rows of data into a table.Final Answer:
INSERT -> Option BQuick Check:
Adding data = INSERT [OK]
Hint: INSERT means putting new data inside [OK]
Common Mistakes:
- Using SELECT to add data
- Confusing CREATE with INSERT
- Thinking DELETE adds data
3. Given the table
Students with columns ID, Name, and Age, what will this SQL query return?SELECT Name FROM Students WHERE Age > 20;
medium
Solution
Step 1: Analyze the SELECT clause
The query selects theNamecolumn only, so the output will be student names.Step 2: Analyze the WHERE condition
The conditionAge > 20filters rows to only those students older than 20.Final Answer:
All student names where age is greater than 20 -> Option AQuick Check:
SELECT Name with Age > 20 = student names over 20 [OK]
Hint: SELECT column filters output; WHERE filters rows [OK]
Common Mistakes:
- Thinking SELECT returns all columns
- Ignoring the WHERE condition
- Confusing column names in SELECT
4. Identify the error in this SQL statement:
INSERT INTO Students (ID, Name Age) VALUES (1, 'Alice', 22);
medium
Solution
Step 1: Check the column list syntax
The columns are listed asID, Name Agewithout a comma betweenNameandAge.Step 2: Confirm correct syntax for INSERT
Column names must be separated by commas. Missing comma causes syntax error.Final Answer:
Missing comma between column names -> Option AQuick Check:
Columns need commas between names [OK]
Hint: Check commas between column names carefully [OK]
Common Mistakes:
- Overlooking missing commas
- Assuming VALUES is misspelled
- Thinking parentheses are extra
5. You have two tables:
Orders(OrderID, CustomerID, Amount) and Customers(CustomerID, Name). Which SQL query correctly lists all orders with the customer names?hard
Solution
Step 1: Understand the relationship between tables
Orders and Customers are linked byCustomerID, so join must use this key.Step 2: Check each JOIN condition
SELECT Orders.OrderID, Customers.Name FROM Orders JOIN Customers ON Orders.CustomerID = Customers.CustomerID; joins onOrders.CustomerID = Customers.CustomerID, which is correct. Others join on wrong columns.Final Answer:
SELECT Orders.OrderID, Customers.Name FROM Orders JOIN Customers ON Orders.CustomerID = Customers.CustomerID; -> Option DQuick Check:
Join tables on matching CustomerID [OK]
Hint: Join tables using matching keys (CustomerID) [OK]
Common Mistakes:
- Joining on wrong columns
- Mixing OrderID with CustomerID
- Using incorrect JOIN types
