Free tool
SQL Formatter with Dialect, Case and Layout Controls
A query copied from a log or an old report is one long line, and nobody can review it. Paste it here, choose the dialect you work in and get a layout your team can read, with an error marker if the query cannot be read.
This file is big, so it is kept out of the text box to keep the page quick. The result is on the right.
The formatted query shows here.
Paste on the left, open a .sql file, or press Example.
Case
Layout
Keys
- Cmd Enter Format
- Cmd Shift Enter One line
- Cmd S Download
- Cmd Shift C Copy
- / Search
Your queries are laid out by your own browser and never uploaded or saved. Only your style choices, such as dialect and keyword case, are remembered on this device.
Turning a pasted query into something reviewable
The Input box starts with a sample query that joins an orders table to customers and items, groups the rows and sorts them. Replace it with your own, open a .sql file, or press Paste. The Result shows the query formatted as you type when Format as I type is on, coloured and numbered, with a search key.
Choose Formatted for the multi-line layout, or One line to squeeze everything into a single line, which is handy for a log message or a command line. The one line mode leaves quoted text alone, so spaces inside a string value are not collapsed.
Nothing here runs the query. The tool only rearranges the text, so it never touches a database.
Choosing the right dialect
Different databases have their own keywords and quoting. The Dialect menu covers a long list, so the formatter knows which words to treat as keywords.
- Everyday choices: Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL) and SQLite.
- Cloud and analytics: BigQuery, Snowflake, Redshift, DuckDB, ClickHouse, Spark SQL, Hive and Trino and Presto.
- Others: Oracle PL/SQL, IBM Db2, IBM Db2 for i, SingleStore, TiDB and Couchbase N1QL.
If the formatter stops with an error on a query that your database accepts, the first thing to try is another dialect. The message gives the line and column, and the line is marked in the input.
Style options in a table
| Setting | What you can pick |
|---|---|
| Keywords | CAPITALS, lower case or as typed |
| Function names, data types | As typed, CAPITALS or lower case |
| Indent | 2 spaces, 4 spaces or tabs |
| Style | Standard, tabular with keywords on the left, or tabular with keywords on the right |
| AND and OR | At the start of a line or at the end |
| Short parts on one line | Up to 30, 50, 80 or 120 characters |
| Comments | Keep them in the form of slash and star pairs, or leave them out |
Pick one house style and use it for every query you share. Agreement matters more than the style itself, since it makes differences between two versions of a query easy to see.
Habits that make queries easier to review
- Format before you paste a query into a ticket or a pull request, so the reviewer reads structure and not one long line.
- Put AND at the start of a line when conditions are long, since the logic reads down the left edge.
- Keep comments in during formatting, then remove them only for the one line version.
- Use the one line version for logs, and the formatted version for people.
Shortcuts: Command Enter formats, Command Shift Enter gives one line, Command S saves a .sql file and Command Shift C copies. On Windows use Control.
A formatter cannot tell you whether a query is correct, fast or safe. It only shows its shape. After formatting, read the joins and the where clause once more, and test any change on a copy of the data before it touches anything real.
Never paste real passwords or private customer values into a query you plan to share, even after formatting.
Where this meets website projects
Reports and data moves often start with a query someone wrote long ago. When a site's content or orders have to be pulled out and reshaped, readable queries save a lot of guesswork. If that is the kind of work in front of you on WordPress, our WordPress development page shows how we scope it.
Frequently asked questions
How do I format a SQL query online?
Paste it into the input box, choose your dialect, and the neat version appears on the right. Then copy it or save it as a .sql file.
Which databases are supported?
The dialect menu includes standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server, SQLite, Oracle, BigQuery, Snowflake and many others.
Does it run my query?
No. It only changes the layout of the text and never connects to a database.
Can I make keywords capital letters?
Yes. Set Keywords to CAPITALS, lower case or as typed. Function names and data types have their own settings.
How do I get the query on a single line?
Press One line. Text inside quotes is left exactly as it was.
Is my SQL saved or sent anywhere?
No. Formatting happens in your browser, and only your settings are kept on your device.
More free tools
- JSON formatter: Format, minify, validate and repair JSON, browse it as a tree, or convert it to YAML or CSV.
- Diff checker: Compare two texts or files side by side, merge changes and export a diff.
- JSON to CSV converter: Turn JSON into CSV or Excel with nested fields as columns, and CSV back into JSON.
- Regex tester: Test a JavaScript regex with live matches, groups, a replace preview and an explanation.
- CSV to JSON converter: Turn a CSV file into JSON, with automatic separator and encoding detection and typed values.