Skip to main content
In this lesson you’ll combine schema design and SQL to build a small relational database from scratch. The goal is a simple backend for a food delivery app called Feline Foods where customers order a single meal-deal combo for delivery. We’ll design the entity-relationship model, choose data types, implement the schema in MySQL, load sample data, and run queries that show how the tables relate. Design the ERD Start by sketching the entities and their attributes. We have three tables: customers, combos, and orders.
  • Customers
    • customer_id — unique identifier, primary key
    • name
    • address
    • contact
  • Combos
    • combo_id — unique identifier, primary key
    • name
    • price
  • Orders
    • order_id — unique identifier, primary key
    • customer_id — foreign key to customers(customer_id)
    • combo_id — foreign key to combos(combo_id)
    • order_time
The image shows a person in a "KodeKloud" t-shirt standing next to a diagram illustrating three database tables: "customers," "combos," and "orders," with their respective primary and foreign keys.
Choose types for each column Use types that match the data and common best practices for small transactional systems:
  • IDs: INT with AUTO_INCREMENT for simple unique identifiers.
  • Names: VARCHAR(100) — variable length and index-friendly.
  • Address: TEXT — can be long and is rarely filtered by equality.
  • Price: DECIMAL — exact storage for currency, e.g., DECIMAL(4,2).
  • Order time: DATETIME.
  • Contact: VARCHAR(20) — phone numbers stored as strings.
Table: Columns and chosen types
Store phone numbers as VARCHAR because they may include leading zeros, country codes, plus signs, or formatting characters (dashes, spaces, parentheses). Numeric types will drop leading zeros and lose formatting.
Define relationships
  • One customer can place zero or many orders (1:N).
  • One combo can appear in zero or many orders (1:N).
  • Each order belongs to exactly one customer and one combo.
  • No separate join table is necessary — the orders table models the association.
The image shows a database schema diagram with tables for "customers," "combos," and "orders," alongside a person gesturing as if explaining the content.
Build the schema in MySQL Create and switch to a new database:
Example mysql session (illustrative):
Create the three tables with appropriate types and foreign key constraints:
Expected confirmation from MySQL:
Foreign key constraints require a storage engine that supports them (e.g., InnoDB). If you get errors creating FKs, ensure your tables use ENGINE=InnoDB or the server default supports foreign keys.
Populate the tables with sample data Insert some customers, combos, and orders. Use proper quoting and valid datetime strings:
Sample output confirming inserts:
Referential integrity Because orders.customer_id and orders.combo_id are foreign keys, every row in orders must reference existing rows in customers and combos. This prevents orphaned references and keeps your data consistent. Reading the data A simple SELECT on the orders table shows only IDs and FK references:
Sample output:
Join tables to produce meaningful results Use JOINs to show which customer ordered which combo and how much it cost:
Result example:
Wrap-up and next steps You now have a compact, working relational schema for Feline Foods: customers, combos, and orders linked by foreign keys. The design enforces referential integrity, uses VARCHAR for phone numbers, DECIMAL for currency, and DATETIME for timestamps. Consider these extensions to make the model more production-ready:
  • Add indexes on frequently queried columns (e.g., customers(name), orders(order_time)).
  • Add order_status, delivery_instructions, or delivery_address to orders.
  • Normalize or denormalize further depending on read/write patterns.
  • Add constraints for data quality (e.g., CHECK on price >= 0).
Links and references

Watch Video

Practice Lab