About this tool
Format SQL online for ten dialects including MySQL, PostgreSQL, SQL Server and Oracle, with indentation and keyword case options, turning one-line queries into readable code.
Typical uses
- Tidy a one-line query printed in logs
- Apply a consistent SQL style across a team
- Beautify complex queries before code review
How to use
Enter or import SQL and choose its dialect, keyword case and indentation.
Select Format or press Ctrl / Command + Enter, then copy or download the SQL.
Choose MySQL and format a single-line SELECT with LEFT JOIN, then select indentation and keyword case to match your style.
Ten dialects. Input up to 200,000 characters, output 500,000, with a five-second timeout. Formatting does not execute SQL or validate database structure. Stored procedures and custom delimiters are unsupported.
Choose the actual database dialect. Formatting success does not prove a query executes or returns correct results. No database connection is made.
What the built-in example looks like after formatting
“Example” fills in a one-line query. With the defaults (MySQL, UPPERCASE, 2 spaces) it becomes 15 lines. A web table collapses leading spaces, so the indent of each line is listed in its own column:
| Line | Indent (spaces) | Text |
|---|---|---|
| 1 | 0 | SELECT |
| 2 | 2 | u.id, |
| 3 | 2 | u.name, |
| 4 | 2 | count(o.id) AS order_count |
| 5 | 0 | FROM |
| 6 | 2 | users u |
| 7 | 2 | LEFT JOIN orders o ON o.user_id = u.id |
| 8 | 0 | WHERE |
| 9 | 2 | u.active = 1 |
| 10 | 2 | AND o.created_at >= '2026-01-01' |
| 11 | 0 | GROUP BY |
| 12 | 2 | u.id, |
| 13 | 2 | u.name |
| 14 | 0 | ORDER BY |
| 15 | 2 | order_count DESC; |
- SELECT, FROM, WHERE, GROUP BY and ORDER BY each get their own line, with their contents one level in. LEFT JOIN sits at the same level as the table name, under FROM.
- Each AND in the WHERE clause starts a new line, spaces are added around = and >=, and commas stay at the end of the line.
- Keyword case changes SQL keywords only. The function name count keeps the lowercase it was typed in, and column names, aliases and the string '2026-01-01' are not touched.
- Several statements can be formatted at once; they are separated by exactly one blank line. select 1; select 2; becomes SELECT ⏎ 1; ⏎ SELECT ⏎ 2; (⏎ marks a line break, with a blank line in between).
Keyword case and indentation
| Setting | Input | Result (⏎ = line break) |
|---|---|---|
| UPPERCASE | select … as order_count … desc | SELECT ⏎ … AS order_count … DESC |
| lowercase | select id from t where name='Select From' -- keep me | select ⏎ id ⏎ from ⏎ t ⏎ where ⏎ name = 'Select From' -- keep me ⏎ and x = 1; |
| Preserve | SeLeCt Id FrOm Users | SeLeCt ⏎ Id ⏎ FrOm ⏎ Users |
- With “lowercase”, the quoted 'Select From' is not lowercased, and the -- comment stays at the end of its line.
- “Preserve” leaves keyword case alone and only changes line breaks and indentation.
- Indentation only sets the width of each level. For an UPDATE with a subquery, the deepest line is indented 6 spaces with “2 spaces”, 12 spaces with “4 spaces”, and 3 tab characters with Tab.
- Changing the input or any option clears the result and shows “Format again after changing the input or options.”; click “Format SQL” or press Ctrl / ⌘ + Enter again. “Use result as input” copies the result back to the left so you can try other settings on it.
What the dialect setting decides
“SQL dialect” offers SQL, MySQL, PostgreSQL, SQLite, SQL Server, MariaDB, BigQuery, Snowflake, Oracle PL/SQL, DuckDB; MySQL is the default. The dialect tells the formatter how to read quotes, placeholders and operators, and the wrong choice can make it fail. It does not check whether the statement would run on that database.
| Dialect | Input fragment | Result |
|---|---|---|
| PostgreSQL | id=$1, data->>'k', created_at::date | id = $1 ⏎ AND data ->> 'k' = 'v' ⏎ AND created_at::date = current_date |
| SQL Server | top 10 [Name], [Users], @id | SELECT ⏎ TOP 10 [Name] ⏎ FROM ⏎ [Users] ⏎ WHERE ⏎ id = @id |
| MySQL | id=? and n=? | id = ? ⏎ AND n = ? |
| MySQL | `a` | Formatted: SELECT ⏎ `a` ⏎ FROM ⏎ t |
| PostgreSQL | `a` | Error: Parse error: Unexpected "`a` from t" at line 1 column 8. |
| MySQL | n=:name | Error: Parse error: Unexpected ":name" at line 1 column 25. |
| MySQL | id=$1 | Formatted: id = $1 |
- PostgreSQL $1 placeholders, ->> and :: casts are recognised and kept as written; SQL Server bracketed names and @variables are kept too.
- MySQL backtick names fail under the PostgreSQL dialect. Switch back to MySQL or MariaDB.
- The last row shows the dialect is not a database check: $1 is not MySQL syntax, yet it is formatted under the MySQL dialect.
- The English detail after the error message comes from the formatting library and gives the line and column. It is cut to 600 characters.
What it does not check, and common messages
| Situation | Result |
|---|---|
| Misspelled keywords: selec id form users | Returned unchanged, with “Formatting complete.” |
| Unclosed string: select 'abc from t | “Could not format this SQL. Check the statement and selected dialect.” + Parse error: Unexpected "'abc from " at line 1 column 8. |
| DELIMITER // and stored procedures | Stops with “Scripts with DELIMITER lines (such as stored procedures) are not supported: formatting would break the delimiter. Remove the DELIMITER lines and format only the plain statements.” |
| Empty input | “Enter SQL first.” |
| More than 200,000 characters | “SQL is limited to 200,000 characters.” |
| Result longer than 500,000 characters | “The result exceeds 500,000 characters. Format smaller sections.” |
| Formatting takes over 5 seconds | “Stopped after 5 seconds. Shorten the SQL or format it in sections.” |
| Importing a file that is not UTF-8 (Windows-1252, for example) | “File must use UTF-8 encoding.” |
- A successful format does not mean the SQL is correct. The tool only re-lays out text; it does not connect to a database or check table names, column names or permissions. drop table users; simply becomes DROP TABLE users; and is never executed.
- The formatting library’s documentation states that stored procedures are not supported, and neither is changing the statement delimiter to anything other than a semicolon. For MySQL scripts with DELIMITER, format only the plain queries.
- “Import SQL” accepts .sql and .txt files up to 800,000 bytes; a leading BOM is removed.
- To see exactly what changed, paste the before and after into the text diff tool.
Sources
Frequently asked questions
Does it run my SQL?
No. It only formats text; it does not connect to a database or check schemas.
Are stored procedures supported?
Stored procedures and custom delimiters are not supported.
Is there a length limit?
Input up to 200,000 characters, output 500,000, with a five-second timeout.
Suggest an improvement to this tool
Missing an option, something awkward to use, or a wrong result? Let us know.