Zero Signup ToolsFree browser tools

Developer Tools

SQL Formatter

Format SQL queries in your browser. Pretty print SELECT, JOIN, CTE, and CASE statements with configurable keyword case, indent, and comma style.

Format SQL

Pretty-print SELECT, INSERT, UPDATE, JOIN, CTE, and CASE queries

Works on standard ANSI SQL plus common syntax from MySQL, PostgreSQL, SQL Server, and SQLite. Comments and string literals are preserved exactly.

Keyword case

Comma style

Indent

Blank lines between statements

266 characters, 1 line.

Formatted SQL

SELECT u. id,
u. email,
count(o. id) AS order_count
FROM users u
LEFT JOIN orders o ON o. user_id = u. id
WHERE u. created_at >= '2025-01-01'
  AND u. status IN('active', 'trial')
GROUP BY u. id,
u. email
HAVING count(o. id) > 0
ORDER BY order_count DESC,
u. email ASC
LIMIT 100;

279 characters, 13 lines. Formatting runs entirely in your browser; the SQL you paste is never uploaded.

How to use

  1. Paste your SQL into the input area on the left, or click a sample (SELECT with JOIN, CTE with window function, CASE expression, INSERT and UPDATE, Subquery) to try the formatter.
  2. Pick a keyword case (UPPER, lower, Capitalize), comma style (trailing or leading), indent unit (2 spaces, 4 spaces, or tab), and how many blank lines to insert between statements.
  3. Optionally toggle 'Always upper-case data types' to keep VARCHAR, INTEGER, and TIMESTAMP upper-cased even in lower-case mode.
  4. Read the formatted query on the right; it updates as you type. Use Copy formatted to grab the result, or Replace with formatted to load it back into the input for another pass.
  5. Comments (-- and /* */) and string literals stay exactly as written, so no behavior changes when you run the formatted query.

About this tool

SQL Formatter is a browser-only SQL beautifier that takes any SELECT, INSERT, UPDATE, DELETE, or DDL statement and re-emits it with consistent indentation, keyword casing, and clause breaks. Paste a single query or a script with multiple semicolon-separated statements on the left and read the formatted result on the right as you type. The tool is built around a small SQL tokenizer plus a clause-aware printer, so it handles the syntax that real-world queries use: CTEs (WITH and WITH RECURSIVE), every JOIN family member (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL, LATERAL, with or without OUTER), GROUP BY, ORDER BY, PARTITION BY, HAVING, LIMIT, OFFSET, FETCH, RETURNING, set operations (UNION, UNION ALL, INTERSECT, EXCEPT), CASE/WHEN/THEN/ELSE/END expressions, window functions with OVER clauses, sub-SELECTs in parentheses, and INSERT VALUES rows. String literals (single quotes), delimited identifiers (double quotes and backticks), line comments (-- to end of line) and block comments (/* ... */) are preserved exactly so the formatted query keeps the same meaning. Configurable options cover the choices teams care about: keyword case (UPPER, lower, or Capitalize) with an optional override that always upper-cases data types like VARCHAR, INTEGER, TIMESTAMP regardless of the global setting; comma style (trailing for the conventional layout or leading for change-friendly diffs); indent unit (2 spaces, 4 spaces, or tab); and the number of blank lines (0, 1, or 2) inserted between statements in a multi-statement script. Top-level clauses (SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, RETURNING, INSERT, UPDATE, SET, MERGE, WITH) start on their own line at the current indentation, JOIN phrases keep their full multi-word form on one line followed by an inline ON predicate, AND and OR connectors break at the same indent so long boolean expressions stay readable, and parenthesized sub-SELECTs descend into a fresh indented block before unwinding. Useful for cleaning up minified queries copied from logs, normalizing query history exports, preparing SQL for a code review or pull request, teaching readable query style, and any time you paste a wall of SQL into a tool that has stripped its formatting. Tokenizing and printing both run on your device, so the queries you paste here, including any production schemas, table names, or business logic embedded in them, never leave your browser.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools