SQL Formatter
This tool formats SQL queries. It puts each clause on its own line, indents lists and conditions, and sets the case of keywords.
- Free, no sign-up
- Nothing is sent to a server
- Worldwide
How to use SQL Formatter online
- Paste the query. Type or paste your SQL.
- Choose the style. Keyword case, indent and commas.
- Read the result. The formatted query appears at once.
- Copy it. Copy or save the result.
Why use this free SQL Formatter
- Clauses on their own lines
- Indented conditions and joins
- Keyword case option
- Strings and comments kept
- Subqueries indented
- Share by link
Readable queries
A long query written on one line is hard to read and to check. The formatter breaks it into lines: SELECT, FROM, WHERE, GROUP BY, ORDER BY and LIMIT each start a line, joins start their own lines, and AND and OR in conditions are indented. The list of columns goes one per line.
What it leaves alone
Text in single quotes, names in double quotes or backticks, and comments are kept exactly as typed, including any semicolons inside them. The tool changes only the spacing, the line breaks and the case of keywords. It never runs the query and never connects to a database, so it is safe to use with queries you do not trust.
A worked example
The one-line query that counts the orders of each active user, with a join, a condition, a group, a having clause and an order, becomes 13 lines:\nSELECT u.id, u.name, COUNT(o.id) AS orders FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.active = 1 AND u.created > '2024-01-01' GROUP BY u.id, u.name HAVING COUNT(o.id) > 2 ORDER BY orders DESC LIMIT 10;\nThe join sits on its own line with its ON condition, the second condition is indented under WHERE, and keywords are in capitals.
Options
Keywords can be written in capitals, in lower case or left as you typed them. The indent is 2 or 4 spaces. Commas can sit at the end of the line, the usual style, or at the start, which some teams prefer because it makes a missing comma easy to spot. Subqueries in brackets are indented one level.
Limits
SQL has many dialects, and the formatter handles the common core: SELECT, INSERT, UPDATE, DELETE, joins, subqueries and basic keywords. Unusual syntax is kept as typed, with spacing tidied. For stored procedures or vendor extensions, the layout may not match your team style, so check the result before you use it.
Using the tool
The result shows under the boxes and refreshes as you edit. Undo and redo step back through your earlier text.
SQL Formatter: frequently asked questions
Does it change my query?
Does it run the SQL?
Are strings and comments safe?
Can I put commas at the start of lines?
Which databases does it support?
Can anyone see the text I put into the SQL Formatter?
Can I save what the SQL Formatter gives me?
Related searches for SQL Formatter
- SQL Formatter online
- free SQL Formatter
- SQL Formatter online free
- SQL Formatter for mobile
- SQL Formatter without sign up
- SQL Formatter – Text & Writing Tools
SQL Formatter is a free online tool on MAITBOX, in the Text & Writing Tools group. It runs in your browser, so what you type is not sent to a server. It works on Android and iPhone, and on Windows, Mac and Linux, with no download and no account.