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.