ERDDiagramTool
Home / Database Schema Templates — SaaS & E-Commerce SQL ERDs

Database Schema Templates (SQL & ERD)

Production-tested SQL DDL blueprints for multi-tenant B2B SaaS workspaces, RBAC memberships, and e-commerce order ledgers ready to paste and visualize.

Copy-Paste Relational Database Schema Blueprints

Starting a new backend service from a blank .sql file often leads to overlooked tenancy boundaries or awkward billing joins months later. Copy any of the normalized production starter schemas below directly into our Free ERD Diagram Tool to visualize, customize, and export your architecture diagram, then verify foreign-key index coverage in the SQL to ERD Linter.

1. Multi-Tenant B2B SaaS Workspace & RBAC Schema

Every tenant-scoped table carries workspace_id or links cleanly back to workspaces so PostgreSQL row-level security (RLS) policies remain straightforward:

CREATE TABLE workspaces (
  id uuid PRIMARY KEY,
  name varchar(120) NOT NULL,
  plan_tier varchar(32) NOT NULL,
  created_at timestamp NOT NULL
);

CREATE TABLE accounts (
  id uuid PRIMARY KEY,
  email varchar(180) UNIQUE NOT NULL,
  password_hash text NOT NULL
);

CREATE TABLE memberships (
  id uuid PRIMARY KEY,
  workspace_id uuid NOT NULL REFERENCES workspaces(id),
  account_id uuid NOT NULL REFERENCES accounts(id),
  role varchar(24) NOT NULL
);

CREATE TABLE projects (
  id uuid PRIMARY KEY,
  workspace_id uuid NOT NULL REFERENCES workspaces(id),
  title varchar(140) NOT NULL,
  archived boolean NOT NULL
);

2. E-Commerce Catalog, Orders & Immutable Line-Item Pricing

Notice how order_items snapshots unit_price_cents as an integer at checkout time rather than relying solely on products.price_cents, ensuring future catalog price changes never alter historical financial ledgers:

CREATE TABLE customers (
  id serial PRIMARY KEY,
  email varchar(180) UNIQUE NOT NULL,
  created_at timestamp NOT NULL
);

CREATE TABLE products (
  id serial PRIMARY KEY,
  sku varchar(64) UNIQUE NOT NULL,
  name varchar(160) NOT NULL,
  price_cents int NOT NULL
);

CREATE TABLE orders (
  id serial PRIMARY KEY,
  customer_id int NOT NULL REFERENCES customers(id),
  status varchar(24) NOT NULL,
  placed_at timestamp NOT NULL
);

CREATE TABLE order_items (
  id serial PRIMARY KEY,
  order_id int NOT NULL REFERENCES orders(id),
  product_id int NOT NULL REFERENCES products(id),
  quantity int NOT NULL,
  unit_price_cents int NOT NULL
);

Unsure how junction tables like memberships or order_items map in cardinality diagrams? Review our Crow's Foot Notation Guide.

Frequently Asked Questions

Why do these SQL templates use integer cents instead of FLOAT for prices?

Storing money as integer cents (or minor currency units) avoids IEEE 754 floating-point rounding bugs that cause penny discrepancies when summing invoices.

Why should order_items copy unit_price_cents instead of joining products?

If a merchant raises a product's price next month, historical order receipts must still reflect the exact unit price the customer paid at checkout.

Can I use these SQL schema templates in commercial projects?

Yes—all sample SQL schemas on ERDDiagramTool are public-domain starter patterns free for commercial and academic software projects.

How do I visualize these templates as an interactive ERD?

Copy any SQL block on this page, open the ERD Designer homepage, paste it into the left SQL DDL editor, and drag tables or export SVG/Mermaid immediately.