Sample database: e-commerce
The e-commerce database is the sample database used throughout this manual. It models an online store for athletic apparel and gear (with a small grocery corner): customers order products, products belong to categories, brands manufacture products and suppliers distribute brands, and everything is located in cities. It also records two social signals: which brands a customer follows and which products a customer likes.
The schema is deliberately hybrid, to show relational and graph data side by side in one database:
- Transactional data (
orders,order_items) and thecountrieslookup are relational tables, queried with standard SQL. - Master data (
customer,product,category,brand,supplier,city) are vertex tables, connected by nine kinds of edges, and are queried with SELECT … MATCH. - Vertex tables can also be read like ordinary tables, and a single query can combine graph patterns with relational tables.
At a glance
Section titled “At a glance”| Object type | Count | Rows |
|---|---|---|
| Relational tables | 3 | 14,114 |
| Vertex tables | 6 | 3,397 nodes |
| Edge tables | 9 | 12,808 edges |
Relational tables
Section titled “Relational tables”| Table | Columns | Rows |
|---|---|---|
orders |
id INT PK, customer_id INT → customer.id, order_date DATE, shipped_date DATE (NULL = not shipped yet), shipping_cost DECIMAL(10,2), ship_address VARCHAR(128) |
2,910 |
order_items |
order_id INT → orders.id, product_id INT → product.id, quantity SMALLINT, discount_pct SMALLINT; PK (order_id, product_id) |
11,179 |
countries |
code VARCHAR(8) PK (ISO 3166 alpha-3), name VARCHAR(32) |
25 |
Vertex tables (nodes)
Section titled “Vertex tables (nodes)”| Vertex table | Columns | Rows |
|---|---|---|
customer |
id INT PK, company_name, contact_name, contact_title, address, phone |
1,000 |
product |
id INT PK, name VARCHAR(64), description VARCHAR(32), unit_price DECIMAL(10,2), units_in_stock SMALLINT |
2,115 |
category |
id INT PK, name, description |
32 |
brand |
id INT PK, name |
106 |
supplier |
id INT PK, company_name, contact_name, contact_title, address, phone |
29 |
city |
id INT PK, name, region, postal_code, country_code → countries.code |
115 |
Edge tables (relationships)
Section titled “Edge tables (relationships)”Every edge has one property, since (DATETIME): when the relationship was recorded.
| Edge | From → to | Cardinality | Meaning | Rows |
|---|---|---|---|---|
part_of |
product → category | N:M | A product belongs to a category | 3,618 |
manufactures |
brand → product | N:M | A brand makes a product | 2,135 |
available_at |
product → supplier | N:1 | A product is sold by a supplier | 2,115 |
distributes |
supplier → brand | N:1 | A supplier distributes a brand | 29 |
follows |
customer → brand | N:M | A customer follows a brand | 1,934 |
likes |
customer → product | N:M | A customer likes a product | 1,842 |
resides_in |
customer → city | N:1 | A customer lives in a city | 1,000 |
located_in |
supplier → city | N:1 | A supplier is based in a city | 29 |
located_at |
brand → city | N:1 | A brand is based in a city | 106 |
The relational tables link to the graph through foreign keys, not edges: orders.customer_id → customer.id, order_items.product_id → product.id, and city.country_code → countries.code.
About the data
Section titled “About the data”The data is synthetic but statistically realistic: orders follow a Pareto distribution per customer (a few frequent buyers, a long tail and about 35% of customers who never order), with holiday seasonality and growth from 2021 to 2025; most order lines have a quantity of 1 to 3 and about 70% have no discount; a few recent orders are still unshipped; and follows / likes are skewed signals correlated with buying. Product names are real-sounding catalog names (for example Chaz Kangaroo Hoodie), and brands are well-known apparel labels (Nike, Adidas, Under Armour, Lululemon, Patagonia …).
Get the database
Section titled “Get the database”The e-commerce database is one of the demo databases included with CoraDB: it is already created and loaded. Start its server if it is not running, then connect with the corasql interpreter:
coradb server start e-commercecorasql -u dba e-commerceCheck the content:
SELECT (SELECT COUNT(*) FROM orders) AS orders, (SELECT COUNT(*) FROM customer) AS customers, (SELECT COUNT(*) FROM product) AS products;| orders | customers | products |
|---|---|---|
| 2910 | 1000 | 2115 |
First queries
Section titled “First queries”A relational query: orders per year.
SELECT EXTRACT(YEAR FROM order_date) AS yr, COUNT(*) AS ordersFROM ordersGROUP BY yrORDER BY yr;A graph query: the brands with the most followers.
SELECT b.name, COUNT(cu) AS followersFROM MATCH (cu:customer)-[:follows]->(b:brand)GROUP BY b.nameORDER BY followers DESCLIMIT 5;A hybrid query: the best-selling products with their category (graph part_of edge + relational order_items).
SELECT p.name AS product, c.name AS category, SUM(oi.quantity) AS total_soldFROM MATCH (p:product)-[:part_of]->(c:category), order_items oiWHERE oi.product_id = p.idGROUP BY p.name, c.nameORDER BY total_sold DESCLIMIT 10;Continue with SELECT and MATCH clause: graph queries in SELECT.