Chapter 15: Create Demo Database

create a complete demo database from scratch! β˜•πŸŽ¬

Up to now we’ve been building tiny pieces (one table β†’ few rows β†’ simple queries). Today we build a realistic mini-project database that feels like something used in a small business or college project β€” something you can keep practicing SELECT, JOIN, GROUP BY, UPDATE, etc. for the next few weeks.

We’re going to create a simple “Online Bookstore” demo database called bookstore_demo.

Why this theme?

  • Easy to understand (books, authors, customers, orders)
  • Allows many-to-many relationships (books ↔ authors, orders ↔ books)
  • Enough data to practice real queries without being overwhelming
  • You can expand it later (add reviews, categories, publishers…)

Step 0: Connect & create the empty database (if not already done)

In psql or pgAdmin Query Tool:

SQL

Step 1: Create the main tables (with good modern PostgreSQL style – 2026 edition)

Run these one by one (or all together):

SQL

After running this β†’ \dt should show 6 tables.

Step 2: Insert realistic sample data (enough to play with)

SQL

Step 3: Quick “It works!” demo queries (playground time)

SQL

Summary – what we just built

Table Purpose Key relationships
authors Store writer info β€”
books Main product catalog β€”
book_authors Many-to-many link books ↔ authors
customers Buyers β€”
orders Purchase headers customers β†’ orders
order_items Line items of each order orders β†’ books (via order_items)

This tiny bookstore database is now your personal playground!

Want to go further?

Tell me:

  • Add more realistic data (10+ books, 20+ customers)?
  • Create views / functions for reports?
  • Add reviews table + ratings?
  • Import from CSV / pagila / dvdrental instead?
  • Or practice complex queries on this schema?

Your call β€” let’s keep building! πŸš€

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *