Building a Simple Relational Database with MySQL
📖 Scenario: You are creating a small database for a bookstore. The store wants to keep track of books and their authors. Each book has a title and belongs to one author. Each author has a name and a country.
🎯 Goal: Build two related tables: authors and books. Link them using a foreign key so you can find which author wrote each book.
📋 What You'll Learn
Create a table called
authors with columns author_id (integer, primary key), name (text), and country (text).Create a table called
books with columns book_id (integer, primary key), title (text), and author_id (integer).Set
author_id in books as a foreign key referencing author_id in authors.Insert sample data into both tables.
Write a query to list all books with their author's name.
💡 Why This Matters
🌍 Real World
Bookstores and libraries use relational databases to organize books and authors so they can quickly find information and manage inventory.
💼 Career
Understanding how to create tables, define relationships, and query data is essential for database administrators, backend developers, and data analysts.
Progress0 / 4 steps