SQL Practice Logo

SQLPractice Online

What is a Relational Database?: Real-World

Module: Foundational Concepts

Relational databases power systems where business facts must stay connected and trustworthy: customers and orders, accounts and transactions, subscriptions and billing, or inventory and fulfillment.

E-Commerce Order Management

An e-commerce system needs customers, orders, products, and order items to stay consistent while still supporting joins across purchasing history, inventory, and revenue reporting.

Normalized tables keep customer and product data consistent while still answering reporting questions quickly.

Find all orders for a customer

SELECT o.order_id, o.order_date, o.status

FROM orders o

WHERE o.customer_id = 12345

ORDER BY o.order_date DESC;

Calculate revenue by product

SELECT p.product_name, SUM(oi.quantity * oi.unit_price) AS revenue

FROM order_items oi

JOIN products p ON oi.product_id = p.product_id

GROUP BY p.product_name

ORDER BY revenue DESC;

All

Banking Transaction System

Banks need accounts, customers, and transactions modeled with strong integrity guarantees and a permanent audit trail.

ACID and relational modeling protect money movement, compliance, and auditability.

Transfer money between two accounts

BEGIN TRANSACTION;

UPDATE accounts SET balance = balance - 100 WHERE account_id = 1001;

UPDATE accounts SET balance = balance + 100 WHERE account_id = 2002;

INSERT INTO transactions VALUES (9001, 1001, 'DEBIT', 100, NOW());

INSERT INTO transactions VALUES (9002, 2002, 'CREDIT', 100, NOW());

COMMIT;

List the latest transactions for an account

SELECT transaction_id, type, amount, timestamp

FROM transactions

WHERE account_id = 1001

ORDER BY timestamp DESC;

All

Social Platform Relationships

A social product tracks users, posts, comments, and friendship edges while still needing reliable ownership and reporting relationships.

The relational model keeps many-to-many relationships, ownership, and lookup paths explicit.

Get the most recent posts from accepted friends

SELECT p.post_id, u.username, p.content, p.timestamp

FROM posts p

JOIN users u ON p.user_id = u.user_id

JOIN friendships f ON f.user_id_1 = 12345 AND f.user_id_2 = p.user_id