SQL Formatter
Format and beautify SQL queries with proper indentation and keyword highlighting.
The SQL Formatter takes a block of raw or minified SQL and rewrites it with consistent indentation, line breaks, and keyword casing so the query becomes easy to read and review. It works entirely in the browser on the text you paste, making it useful for cleaning up queries copied from logs, ORMs, or a colleague who never pressed Enter.
How to use it
- Paste your SQL into the input box, or type it directly. A single long line or a wall of nested subqueries both work.
- Choose your options if available, such as the SQL dialect and whether keywords should be uppercased or lowercased.
- Run the formatter. The output panel shows the reindented query with one clause per line.
- Copy the formatted result back into your editor, migration file, or pull request.
Because formatting only rearranges whitespace and casing, the query's logic and results stay identical. Always run the output against your database before relying on it.
How SQL formatting works
A formatter parses the statement into tokens, recognises SQL keywords like SELECT, FROM, WHERE, JOIN, and GROUP BY, then reassembles them with predictable rules. Major clauses start on new lines, joined tables and conditions are indented beneath them, and comma-separated columns are aligned so each is visible at a glance. Keyword casing is normalised, typically to uppercase, which separates SQL syntax from your table and column names.
Readable SQL matters because queries are read far more often than they are written. Consistent layout makes diffs in version control smaller and clearer, helps reviewers spot a missing join condition or an accidental Cartesian product, and lowers the chance of bugs hiding in a dense one-liner. Different dialects, such as PostgreSQL, MySQL, SQL Server, and SQLite, share most keywords but differ on functions and quoting, so picking the matching dialect produces the cleanest result.
FAQ
Does formatting change what my query returns?
No. The tool only adjusts whitespace, line breaks, and the casing of recognised keywords. The tables, columns, conditions, and order of operations are untouched, so the query produces the same results.
Which SQL dialects are supported?
The formatter handles standard SQL keywords and common dialects including PostgreSQL, MySQL, SQL Server, and SQLite. Selecting the dialect that matches your database gives the most accurate handling of dialect-specific syntax and identifier quoting.
Can I control keyword casing and indentation?
Yes. Keywords can be rendered in uppercase or lowercase, and the formatter applies consistent indentation to clauses and nested expressions so the structure of the statement is visible.
What are common formatting pitfalls?
Vendor-specific functions, unusual quoting, or syntax errors can confuse any parser, so check the output for queries that fail to format cleanly. Avoid forcing keyword casing onto case-sensitive identifiers, and always test the formatted SQL against your database before committing it.
Related Tools
JSON Formatter
Pretty-print, validate and minify JSON
Base64 Encoder/Decoder
Encode and decode Base64 strings and files
Colour Picker
Pick colours and convert between HEX, RGB and HSL
UUID Generator
Generate random UUID v4 identifiers
URL Encoder/Decoder
Encode and decode URLs and query strings
Regex Tester
Test regular expressions with match highlighting