⚙️ Settings
WITH recent_orders AS (
SELECT
customer_id,
order_id,
order_date,
total_amount
FROM orders
WHERE order_date >= DATEADD(day, -30, GETDATE())
)
SELECT
customer_id,
COUNT(order_id) AS order_count,
SUM(total_amount) AS total_spent
FROM recent_orders
GROUP BY customer_id
ORDER BY total_spent DESC;
WITH RECURSIVE employee_hierarchy AS (
-- Anchor: top-level rows (no manager)
SELECT
employee_id,
manager_id,
employee_name,
1 AS level
FROM employees
WHERE manager_id IS NULL
UNION ALL
-- Recursive: join children to their parent's result
SELECT
e.employee_id,
e.manager_id,
e.employee_name,
eh.level + 1
FROM employees e
INNER JOIN employee_hierarchy eh
ON e.manager_id = eh.employee_id
)
SELECT *
FROM employee_hierarchy
ORDER BY level, employee_name;
-- Note: SQL Server / Oracle: drop the RECURSIVE keyword (just WITH employee_hierarchy AS (...))
SELECT
o.order_id,
c.customer_name,
o.order_date,
p.product_name,
oi.quantity
FROM orders o
INNER JOIN customers c
ON o.customer_id = c.customer_id
LEFT JOIN order_items oi
ON o.order_id = oi.order_id
LEFT JOIN products p
ON oi.product_id = p.product_id
WHERE o.order_date >= '2026-01-01'
ORDER BY o.order_date DESC;
SELECT
DATE_TRUNC('month', order_date) AS order_month, -- PostgreSQL
-- FORMAT(order_date, 'yyyy-MM') AS order_month, -- SQL Server
-- DATE_FORMAT(order_date, '%Y-%m') AS order_month, -- MySQL
COUNT(*) AS order_count,
SUM(total_amount) AS revenue
FROM orders
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY order_month;
SELECT
customer_id,
order_id,
order_date,
total_amount,
ROW_NUMBER() OVER (
PARTITION BY customer_id
ORDER BY order_date DESC
) AS order_rank,
SUM(total_amount) OVER (
PARTITION BY customer_id
ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS running_total
FROM orders;
CREATE PROCEDURE GetCustomerOrders
@CustomerId INT,
@StartDate DATE = NULL,
@EndDate DATE = NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT
order_id,
order_date,
total_amount
FROM orders
WHERE customer_id = @CustomerId
AND (@StartDate IS NULL OR order_date >= @StartDate)
AND (@EndDate IS NULL OR order_date <= @EndDate)
ORDER BY order_date DESC;
END;
-- Call it: EXEC GetCustomerOrders @CustomerId = 101, @StartDate = '2026-01-01';
MERGE INTO customers AS target
USING staging_customers AS source
ON target.customer_id = source.customer_id
WHEN MATCHED THEN
UPDATE SET
target.customer_name = source.customer_name,
target.email = source.email,
target.updated_at = GETDATE()
WHEN NOT MATCHED THEN
INSERT (customer_id, customer_name, email, created_at)
VALUES (source.customer_id, source.customer_name, source.email, GETDATE());
#FACC15
rgb(250, 204, 21)
rgb(98%, 80%, 8%)
hsl(46, 96%, 53%)
hsv(46, 92%, 98%)
cmyk(0%, 18%, 92%, 2%)
ER Diagram Designer — Design Database Schemas Online
The ER Diagram Designer lets you visually design database schemas — add tables, define columns with data types and PK/FK keys, and draw relationships between them — then export the result as a PNG. It's built for developers, analysts, and students who need to create an ER diagram online while planning a database structure, documenting an existing schema, or studying entity-relationship modeling, without installing dedicated database design software.
⚡ Key Takeaways
- Visually models tables, typed columns, and PK/FK relationships between them.
- Connects specific columns to each other, not just whole tables.
- Twelve common SQL data types available directly from a dropdown per column.
- A planning and documentation aid — it doesn't generate or run actual SQL DDL.
What, Who, When & Why
| What it's for | A visual tool for designing database schemas — tables, typed columns, keys, and relationships between them. |
|---|---|
| Who it's for | Developers, analysts, and students planning or documenting a database structure. |
| When to use it | Before writing CREATE TABLE statements, or when documenting or teaching an existing schema's structure. |
| Why it's needed | Planning a schema in text or in your head makes relationships hard to visualize; a diagram makes table connections immediately clear. |
| Best way to use it | Mark primary and foreign keys as you go, and connect specific columns (not just whole tables) to precisely represent each relationship. |
How to Use the ER Diagram Designer
- Click Add Table to create a new table with starter columns.
- Rename the table using its header, then add or edit columns with a name, data type, and PK/FK badges.
- Drag a column's blue dot onto another column to draw a relationship line between them.
- Click a relationship line to select it, then click 🗑 to delete it, or drag an endpoint to repoint it.
- Drag a table's header to move it, or its corner handle to resize it.
- Click 📸 to export the finished diagram as a PNG.
Available Column Data Types
Each column can be assigned a data type from a dropdown, including: INT, BIGINT, VARCHAR, TEXT, BOOLEAN, DATE, DATETIME, TIMESTAMP, FLOAT, DECIMAL, UUID, and JSON — covering the most common types used across relational database systems.
Example
A simple two-table schema might have a users table with columns id (INT, PK) and email (VARCHAR), and an orders table with id (INT, PK) and user_id (INT, FK). Dragging a connection from the users.id column to orders.user_id visually represents the one-to-many relationship between customers and their orders — exactly the kind of relationship a foreign key enforces in a real database.
Key Features
- Add unlimited tables, each with editable names and columns.
- Twelve common SQL data types available per column.
- Primary Key (PK) and Foreign Key (FK) badges for each column.
- Drag-to-connect relationships between specific columns, not just whole tables.
- Repointable and deletable relationship lines.
- Drag-to-reorder columns within a table.
- Color-coded tables for visual organization.
- Resizable tables and a full-screen expand mode.
- Export the finished schema diagram as a PNG.
- Auto-saves to your browser between visits.
Practical Use Cases
- Planning a new database: sketch out tables and relationships before writing any CREATE TABLE statements.
- Documenting an existing schema: visually map out how an existing database's tables relate to each other.
- Teaching or learning database design: practice entity-relationship modeling concepts with a visual, hands-on tool.
- Reviewing schema changes: sketch a proposed schema change to discuss with a team before implementation.
Related Terminology
An ER diagram (Entity-Relationship diagram) visually represents a database's tables (entities) and how they relate to one another. A Primary Key (PK) uniquely identifies each row in a table, while a Foreign Key (FK) is a column that references a primary key in another table, establishing a relationship between the two.
Important Considerations
This tool is a visual planning and documentation aid — it doesn't generate or execute actual SQL CREATE TABLE statements, and it doesn't validate that your relationships match real database constraints. Use it to plan and communicate a schema design, then write the actual DDL separately.
Related Tools
Once you've planned your schema, the SQL Query Templates can help you write the actual table-creation and query SQL. For more general-purpose diagramming beyond database schemas, try the Flow Planner.
Frequently Asked Questions
Does this tool generate actual SQL CREATE TABLE statements?
No, it's a visual planning and documentation tool — it helps you design and communicate a schema, but you'll write the actual SQL DDL separately based on your design.
How do I mark a column as a primary key?
Click the PK badge next to that column to toggle it on — the badge highlights to show the column is marked as a primary key.
Can I connect specific columns, not just entire tables?
Yes, drag from a specific column's connection dot to another specific column to draw a precise, column-level relationship line.
Can I export my ER diagram as an image?
Yes, click the 📸 export button to download the complete diagram, including all tables and relationships, as a PNG image.
Tools for analysts, developers & QA engineers
33 free, browser-based utilities — text and list tools, SQL helpers, converters, and small productivity apps. Everything runs locally; nothing you type or paste is ever uploaded.
For Analysts
Clean lists, build SQL fragments, and reshape data without opening a spreadsheet.
For Developers
Format SQL, convert data formats, and handle everyday text and encoding tasks.
For QA Engineers
Generate test data, compare text output, and sanitize queries before sharing them.