↑

Free SQL Formatter

What this tool does

The SQL Formatter turns messy queries into clean, readable SQL. It puts each clause on its own line, uppercases keywords, and normalizes spacing around commas, operators and parentheses, while leaving string literals and comments untouched. A minify mode does the opposite, squeezing a query onto one line for logs or code. Paste a SELECT, INSERT, UPDATE or DELETE statement and copy the result. Free and private in your browser.



-
Output characters
-
Output lines
-
Statements
-
Size change
Output
Strings and comments are never changed. Formatting puts each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY) on its own line.

Let us know

Please share your experience with this tool.

Thanks for rating!
No ratings yet — be the first!

How do I format a SQL query?

Paste your query and it is reformatted instantly: each major clause moves to its own line, keywords are uppercased, and spacing around commas, operators and parentheses is normalized. The built-in example goes from one long line to seven readable lines: SELECT with the column list, then FROM, LEFT JOIN ... ON, WHERE, GROUP BY, ORDER BY and LIMIT each starting a fresh line. Function calls stay tight (COUNT(o.id), not COUNT ( o.id )), table.column names keep their dot, and strings like '2026-01-01' are never touched. You can turn keyword uppercasing off if your team prefers lowercase keywords.

What does the formatter change, and what does it leave alone?

It changes layout only, never meaning. Clause starters (SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, UNION, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, and every JOIN type) begin new lines at the top level; inside parentheses the query stays inline so subqueries and IN lists remain compact. String literals in single quotes, double quotes or backticks are preserved character for character, including doubled-quote escapes, and both -- line comments and /* block comments */ survive formatting, each on its own line. Keywords inside strings are not uppercased and do not trigger line breaks, so a value like 'select from where' stays exactly as written.

When should I minify SQL instead?

Minify mode squeezes a query onto a single line by removing unnecessary whitespace while keeping the spaces SQL actually needs between words. The formatted example (7 lines) minifies back to a single line. Minified SQL is handy for log lines, config files, environment variables, and embedding a query in code or a URL where newlines cause trouble. It is the same query with the same meaning; databases do not care about whitespace. Keep the formatted version in your source files for humans, and minify only the copy that goes into a machine-facing place.

Which SQL dialects does it work with?

The formatter works on the common core shared by MySQL, PostgreSQL, SQLite, SQL Server and standard SQL: SELECT, INSERT, UPDATE, DELETE, joins, grouping, ordering, unions and basic DDL such as CREATE TABLE, ALTER TABLE and DROP TABLE. Dialect-specific syntax passes through unchanged because the formatter only rearranges whitespace and keyword case; it never rewrites identifiers, operators or values. Statements are counted by semicolons, so a script with an INSERT, an UPDATE and a DELETE reports 3 statements, and each one is formatted independently. Vendor functions outside the built-in list keep their original case, which is safe if slightly less uniform.

Why format SQL at all?

Readable queries are easier to review, debug and hand over. A clause-per-line layout makes missing commas, wrong join conditions and accidental full-table updates visible at a glance: in a one-line UPDATE, the WHERE clause hides at the end; formatted, its absence is obvious. Consistent keyword casing lets you scan structure quickly, and normalizing a query before pasting it into a pull request, a ticket or documentation saves every reader time. Formatting before comparing two query versions also makes diffs show real changes instead of whitespace noise. It takes one paste, so there is little excuse for shipping a 400-character one-liner.

Is it free and private?

Yes. The SQL formatter is free, with no signup, no account and no limits. Formatting runs entirely in your browser, so your queries, table names and data values are never sent to a server, stored or logged, which matters when production SQL contains sensitive schema details. For developers, analysts and DBAs who read and write SQL every day, this page does the job in seconds.

FAQs

Does formatting change what my query does?

No. Only whitespace and keyword case change. Strings, comments, identifiers and values are preserved exactly.

Will keywords inside strings be uppercased?

No. Text inside quotes is never touched, so a value like 'select from where' stays as written.

Can it format INSERT, UPDATE and DELETE?

Yes. INSERT INTO, VALUES, UPDATE, SET and DELETE FROM each get their own line, and multiple statements are handled together.

What is minify mode for?

It squeezes a query onto one line for logs, config files and embedding in code, keeping only the spaces SQL needs.

Which databases does it support?

The common SQL core used by MySQL, PostgreSQL, SQLite and SQL Server. Dialect-specific parts pass through unchanged.

Is my data stored anywhere?

No. Formatting runs in your browser. Queries are never sent to a server or stored.


Author

Awais Arshad

Web Tools Developer & Content Creator at FastToolKit.