SQL Formatter & Beautifier

Paste any SQL query and format it with proper line breaks and keyword casing. Supports SELECT, INSERT, UPDATE, DELETE, JOINs, CTEs, and more. Runs entirely in your browser.

Developer Tools Cluster

SQL Input — paste unformatted SQL
📄 Drop a .sql file here, or
Formatted SQL

What This Tool Does

Formats and beautifies SQL queries with proper indentation, keyword capitalization, and consistent spacing — entirely in your browser. Supports MySQL, PostgreSQL, SQL Server, SQLite, and standard ANSI SQL.

Who This Is For

  • Developers reviewing one-line SQL queries copied from ORMs, logs, or error messages
  • DBAs standardizing SQL code style across a team or codebase
  • Data analysts making complex queries readable before sharing with colleagues
  • Anyone copy-pasting SQL from documentation that arrives as a dense single line

Example: Input: A minified query like select u.id,count(*) from users u join orders o on u.id=o.user_id where o.status='complete' group by u.id having count(*)>5 → Output: A properly indented, keyword-uppercased SQL query that's immediately readable and ready for a code review

How to Format SQL

  1. Paste your SQL query (or multiple queries) into the input field.
  2. Select your SQL dialect: SQL Server (T-SQL), MySQL, PostgreSQL, or generic SQL.
  3. Click Format. The output shows the query with consistent indentation and keyword casing.
  4. Copy the formatted SQL or use it directly.

The formatter handles SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER TABLE, CTEs (WITH clauses), subqueries, and window functions.

What Good SQL Formatting Looks Like

Unformatted (hard to read):

select u.id,u.name,count(o.id) as order_count from users u left join orders o on u.id=o.user_id where u.created_at>'2026-01-01' group by u.id,u.name having count(o.id)>0 order by count(o.id) desc limit 100

Formatted (immediately readable):

SELECT
    u.id,
    u.name,
    COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o
    ON u.id = o.user_id
WHERE u.created_at > '2026-01-01'
GROUP BY
    u.id,
    u.name
HAVING COUNT(o.id) > 0
ORDER BY COUNT(o.id) DESC
LIMIT 100;

The structure, JOIN conditions, and filtering logic are immediately visible in the formatted version.

SQL Formatting Conventions

ElementConventionExample
KeywordsUPPERCASESELECT, FROM, WHERE, JOIN
Table/column nameslowercase or quotedusers, order_id
Indentation2 or 4 spaces per levelSubqueries indented inside
Column listOne per lineEach column on its own line
JOIN conditionsIndented under JOINON clause indented
CTEsEach on its own blockWITH cte1 AS (...), cte2 AS (...)

These conventions are not enforced by the database — SQL is whitespace-insensitive. They are for human readability, code review, and maintenance.

SQL Formatting in Development Workflows

SQL Development Workflow

SQL formatting is part of a complete SQL development and analysis workflow:

Related Tools

Related Guides & Tutorials

Frequently Asked Questions

Does SQL formatting affect performance?
No. SQL is whitespace-insensitive. The query optimizer generates the same execution plan regardless of formatting. Formatting is purely for human readability.
What SQL dialects does this formatter support?
The formatter supports SQL Server (T-SQL), MySQL, PostgreSQL, and generic ANSI SQL. Select the appropriate dialect for syntax-specific formatting and keyword handling.
Why do some SQL keywords not get uppercased?
Function names, table names, and column names are left in their original case — the formatter only changes SQL keywords (SELECT, FROM, WHERE, etc.) to uppercase. This avoids breaking case-sensitive identifiers.
Can I format multiple queries at once?
Yes. Paste multiple statements separated by semicolons. Each statement is formatted individually.
Should SQL keywords be uppercase?
This is a convention, not a rule. Most style guides recommend uppercase keywords for readability — it clearly distinguishes the structure of the query from the data-specific names. Some teams prefer lowercase for aesthetics. Consistency within a codebase is what matters.
How do I handle SQL with CTEs?
CTEs (WITH name AS (...)) are fully supported. The formatter will indent the CTE body and align multiple CTEs consistently.