An end‑to‑end relational schema for a marketplace platform built on PostgreSQL, complete with sample data, retrieval queries, and an ERD diagram.
DB Creation, Tables Creation, Data Insertion.sql: Creates themarketplacedatabase, all tables, constraints, and loads realistic sample data.Queries (Retrieval).sql: A collection of read-only queries to analyze the dataset (joins, filters, aggregations).Query Results/: CSV outputs for the retrieval queries.ERD.png: The entity–relationship diagram summarizing the schema.
Users: Core user profile fields with basic constraints (unique email, gender check, etc.).Addresses: Mailing addresses for users; cascades on user deletion.ShopOwnersandRegularUsers: Role tables referencingUsers.Shops: Stores with rating and sales volume; owned by aUser.Categories: Product/shop categories.ShopCategories: Many‑to‑many relation betweenShopsandCategories.Products: Catalog with pricing, stock, shipping meta and description.ShopProducts: Many‑to‑many relation betweenShopsandProducts.Orders: Purchases by users, with shipping/payment metadata and notes.OrderProducts: Line items for each order.Messages: Simple direct messaging between users.ProductReviews: Star ratings and text reviews for products.Admins: Admin users referencingUsers.
Refer to the DDL file for exact column types, constraints, and keys.
Prerequisites:
- PostgreSQL 15+ (or a compatible version)
psqlCLI or a GUI (PgAdmin, DBeaver, etc.)
- Create database, tables, and load sample data
Using psql:
# From the repository root
psql -U postgres -f "DB Creation, Tables Creation, Data Insertion.sql"This script will:
- Create the
marketplacedatabase - Define all relations and constraints
- Insert realistic sample data
- Reset sequences to align with inserted IDs
- Run retrieval queries
psql -U postgres -d marketplace -f "Queries (Retrieval).sql"Result sets for representative queries are provided under Query Results/.
-- Total orders and revenue by shipping method
SELECT shipping_method,
COUNT(*) AS num_orders,
ROUND(SUM(total_price)::numeric, 2) AS gross_revenue
FROM Orders
GROUP BY shipping_method
ORDER BY gross_revenue DESC;