Developer Tools
SQL Formatter
Format and beautify SQL queries for PostgreSQL, MySQL, SQL Server, SQLite, BigQuery and more, with uppercase keywords.
How to use
- 1Paste your SQL and choose the database dialect.
- 2Copy the formatted query.
Frequently asked questions
Does formatting change what my query does?
No. Only whitespace, line breaks and keyword case change; identifiers, values and logic are untouched.
Why choose a dialect?
Databases differ in syntax — backtick identifiers in MySQL, :: casts in PostgreSQL, square brackets in SQL Server. The dialect makes sure these are parsed correctly.
Can it format several statements at once?
Yes. Separate statements with semicolons and each is formatted in turn.
Why the dialect dropdown matters more than it looks
This isn't cosmetic — the underlying sql-formatter library actually parses your query against grammar rules specific to the chosen dialect, so picking the wrong one causes real breakage: PostgreSQL's :: cast operator, MySQL's backtick-quoted identifiers, SQL Server's [bracketed] names and BigQuery's backtick table paths (`project.dataset.table`) are each only recognized when that dialect is selected. A query that formats fine under 'Standard SQL' can throw a parse error, or silently mis-tokenize, under a different engine's syntax — so when in doubt, match the dropdown to the database you're actually querying rather than leaving it on the default.
What changes, and the guarantee that nothing else does
Only whitespace, line breaks and keyword letter-casing are touched; identifiers, string literals and operator logic pass through unmodified, which is why formatting is safe to run on production queries before a code review — it can never change what the query returns. That also means it won't catch a wrong JOIN condition or a missing WHERE clause; it's a readability tool, not a linter or an EXPLAIN plan.
Multi-statement scripts and when this beats an editor plugin
Because statements are split on semicolons and each is parsed and formatted independently, pasting an entire migration script with a dozen CREATE/ALTER/INSERT statements works in one pass — something many editor-embedded formatters choke on or apply inconsistently across. This runs entirely in your browser (no query text is sent anywhere), so it's reasonable to paste real queries containing production table and column names without that data leaving your machine.
Worked example: SQL Formatter
Paste `select a,b from t where x=1 and y='z'` with Standard SQL and default settings, and the output is: SELECT a, b FROM t WHERE x = 1 AND y = 'z' Each selected column and the WHERE condition drop to their own line, keywords are uppercased, and the literal `'z'` stays exactly as written. Switch the dialect to MySQL and turn off uppercasing on `select \`a\` from \`t\`` and the backtick-quoted identifiers are preserved with keywords left lowercase, since that's dialect- and toggle-specific behavior, not a fixed house style.
Turning uppercase off keeps the case I typed
Dialect opens on Standard SQL. Uppercase keywords starts on, so words like select come back as SELECT. Turning it off preserves the case I typed instead of forcing lowercase. Indent opens on 2 spaces, with 4 spaces or a tab as the other choices. A tab indent is two tab stops wide. The download is a .sql file. A script that will not parse stops with "Couldn't parse that SQL" and only the first line of the reason. I use that when a quote is missing and I do not want the rest of the stack in the message.
Related tools
- Code Beautifier (HTML, CSS, JavaScript)
Beautify messy or minified HTML, CSS and JavaScript into clean, consistently indented code you can read and edit.
- XML Formatter & Validator
Pretty-print and validate XML with readable indentation, or minify it — errors point to the exact line and column.
- JSON Formatter & Validator
Format, beautify, validate and minify JSON — with clear line and column error messages and optional key sorting.
- CSV to SQL INSERT Generator
Generate SQL CREATE TABLE and INSERT statements from CSV data for MySQL, PostgreSQL, SQLite or SQL Server.
- SQL to MongoDB Query Converter
Translate SQL into MongoDB queries — SELECT with WHERE (AND/OR, IN, LIKE, BETWEEN, IS NULL), ORDER BY, LIMIT, GROUP BY aggregations, plus INSERT, UPDATE and DELETE.
- JSONPath Tester
Query JSON with JSONPath expressions like $.store.book[*].author or $..price and see every match with its exact path.