SQL Formatter
Format and beautify SQL queries for better readability.
Why SQL formatting matters
Unformatted SQL is one of the most common sources of bugs and misunderstandings in software development. A 200-character single-line query is nearly impossible to review, debug, or optimise. Well-formatted SQL with consistent indentation, uppercase keywords, and logical line breaks makes the query structure immediately obvious β joins, conditions, and subqueries become visually distinct sections rather than an undifferentiated string.
SQL formatting conventions
| Element | Convention | Reason |
|---|---|---|
| Keywords (SELECT, FROM, WHERE) | UPPERCASE | Visually distinguishes SQL syntax from data and identifiers |
| Column and table names | lowercase or snake_case | Consistent with most database naming conventions |
| Each clause on a new line | SELECT / FROM / WHERE / ORDER BY | Makes query structure immediately readable |
| Indent subqueries | 2 or 4 spaces | Shows nesting depth and query logic |
| Aliases after AS keyword | explicit AS keyword | Clearer than implicit aliases; self-documenting |
| Line up columns in SELECT | vertically aligned | Easier to scan a long list of columns |
Before and after: a real query
BEFORE (unformatted):
select u.id,u.name,u.email,o.total from users u inner join orders o on u.id=o.user_id where u.active=1 and o.total>100 order by o.total desc limit 10
AFTER (formatted):
SELECT
u.id,
u.name,
u.email,
o.total
FROM users AS u
INNER JOIN orders AS o
ON u.id = o.user_id
WHERE
u.active = 1
AND o.total > 100
ORDER BY o.total DESC
LIMIT 10SQL dialect differences
While the SQL standard (ANSI SQL) defines core syntax, each database system has its own dialect with extensions and quirks. Formatted SQL from one system may not run unmodified in another. The most common differences affecting formatting and syntax:
String quotes:
PostgreSQL, MySQL: 'single quotes' for strings
SQL Server: N'unicode strings' prefix for Unicode
Limit/offset:
MySQL, PostgreSQL: LIMIT 10 OFFSET 20
SQL Server: TOP 10 ... (or OFFSET/FETCH NEXT in modern versions)
Oracle: ROWNUM or FETCH FIRST n ROWS ONLY
Date functions:
MySQL: NOW(), DATE_FORMAT()
SQL Server: GETDATE(), FORMAT()
PostgreSQL: NOW(), TO_CHAR()Frequently asked questions
Does formatting change my query results?
No. Formatting only adds indentation and line breaks for readability β the SQL logic and the results it returns are completely unchanged.
Which SQL dialects does this support?
It works with the standard SQL used by MySQL, PostgreSQL, SQL Server, SQLite and others. Dialect-specific syntax is preserved as written.
Is my SQL sent to a server?
No. Formatting runs entirely in your browser, so your queries and any data in them stay private on your device.
Why bother formatting SQL at all?
Readable, consistently indented SQL is far easier to review, debug and maintain, and it reduces mistakes in complex joins, subqueries and long WHERE clauses.