SQL Formatter
Paste a query and this SQL formatter lays it out as you type: clauses on their own lines, subqueries and CASE indented, keywords in the case you choose. Seven dialects, a one-line minify mode and checks for unclosed quotes and brackets. Your SQL stays in your browser and is never run.
- Free, no sign-up
- 7 SQL dialects
- Format or minify
- Unclosed quotes found
- Queries never run
- Nothing uploaded
People also use
How to format SQL in three steps
Type or paste SQL in the left box, or press Open .sql file, and the formatted version appears on the right straight away. There is no Format button to press: the output follows every change you make, and a small counter shows how many lines and statements it holds. Copy puts the result on your clipboard, and Download .sql saves it as a file.
The page is built around one rule: it may move spaces and line breaks, and it may change the letter case of SQL keywords if you ask, but it never touches what the query means. Text in quotes, quoted table and column names, numbers and comments come out exactly as they went in.
Pick your dialect from the list first. MySQL, PostgreSQL, SQL Server, Oracle, SQLite and BigQuery each quote names and write comments a little differently, and the tool needs to know which rules apply so it can tell a string from a name and a comment from an operator.
- 1
Paste or open your SQL
Type or paste one or more statements into Your SQL, or press Open .sql file to load a .sql or .txt file from your device. Choose the matching database in the Dialect list.
- 2
Choose the layout
Keep Format (beautify) for readable SQL, or switch to Minify (one line). In format mode, set Keywords, Indent and commas, and the Lines options to match your team's style.
- 3
Copy or download
Press Copy to put the result on your clipboard, or Download .sql to save it. If a quote, comment or bracket is not closed, a red message with the line and column appears instead.
Your settings, such as the dialect, keyword case, indent and comma style, are remembered in this browser for next time. The SQL you type is not saved: reload the page and the box shows the sample query again.
Before and after: one query, formatted
Here is a typical one-line query of the kind that ends up in logs, debug output or a chat message. It has a CASE expression, a join and a subquery.
select u.id, u.name, case when o.total > 100 then 'big' else 'small' end as size from users u join orders o on o.user_id = u.id where o.id in (select order_id from refunds where amount > 0) and u.active = 1 limit 10;With the default settings (Standard SQL, UPPER keywords, 2 spaces, commas at line end, AND / OR on their own lines), the result is:
SELECT
u.id,
u.name,
CASE
WHEN o.total > 100 THEN 'big'
ELSE 'small'
END AS size
FROM
users u
JOIN orders o
ON o.user_id = u.id
WHERE
o.id IN (
SELECT
order_id
FROM
refunds
WHERE
amount > 0
)
AND u.active = 1
LIMIT 10;Each main clause, SELECT, FROM and WHERE, starts at the left edge, and the items under it are indented one step. The select list puts one column per line, with the comma at the end of the line.
The CASE expression gets its own block: each WHEN and the ELSE sit one step deeper, and END lines up with CASE. The JOIN starts a new line and its ON condition goes on the next line, indented, so long join conditions are easy to scan.
The subquery inside IN ( ) is laid out as a query of its own, one level deeper, and the closing bracket returns to the level of the condition it belongs to. The AND after it starts its own line. Short clauses such as LIMIT 10 stay on one line, because there is nothing to list.
Notice what did not change: 'big', 'small', the table aliases and the column names. Only keywords were capitalised and only whitespace moved.
SQL formatter online: paste, read, copy
A query copied from an application log usually arrives as one long line. A sql formatter online is the fastest way to turn it into something you can read: paste, look at the right-hand box, and the structure is visible. Because everything happens in the page, the result updates while you type, even on long scripts.
The output box is read-only, so you cannot change the result by accident. To try a different layout, change a setting rather than editing the output; the input stays exactly as you left it. Clear empties the input box when you want to start over.
Several statements can go in at once. Each semicolon ends a statement, the counter above the output tells you how many it found, and the Empty lines between statements setting decides whether they are separated by 0, 1 or 2 blank lines.
A SQL formatter free of sign-ups, limits and uploads
You get a sql formatter free of accounts, quotas and upgrade screens: paste as much SQL as you like, as often as you like. There is no paid version with extra options, so every setting described on this page is available to everyone.
Because the formatting runs in your browser, there is no server cost per query, and so no reason to limit how many queries you format or how long they are. Very large scripts depend only on the speed of your device; a typical query is formatted before you finish typing.
The output is plain SQL text with nothing added: no header, no watermark, no tracking comment. What you copy is ready to paste into your editor, a migration file, a pull request or a ticket.
SQL formatter and beautifier: what changes and what never does
A sql formatter and beautifier should make a query easier to read without any risk of making it do something different. This one works in two stages. First a tokenizer reads your SQL piece by piece and labels every part: word, text in quotes, quoted name, number, comment, operator, bracket, comma or semicolon. Then the layout step joins those pieces again with new spaces and line breaks.
The pieces themselves are never edited. A string such as 'it''s here' keeps its doubled quote, a name such as "Order Date" keeps its space and capitals, 1.50e3 stays 1.50e3, and a comment keeps every character. Placeholders such as ?, :name, @name and $1 are kept as they are too.
The only things that change are whitespace and, if you choose, the case of SQL keywords. With Keyword case set to UPPER, words such as select, from, left join and group by become SELECT, FROM, LEFT JOIN and GROUP BY, and common function names written before a bracket, such as count( or coalesce(, become COUNT( and COALESCE(. With lower, keywords become lowercase and function names stay as typed. A word right after a dot, as in t.order, is treated as a column name and left alone. Keep as typed leaves every word exactly as you wrote it.
What it does not do is rewrite the query. It does not add or remove brackets, reorder columns, expand SELECT *, add aliases or change join syntax. That is deliberate: the formatted SQL should return exactly what the original returned.
How each kind of statement is laid out
SELECT
Each main clause, SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT, starts a new line at the left edge. SELECT, GROUP BY and ORDER BY put one item per line; FROM, WHERE and HAVING put their content on the next line, one step in. UNION, UNION ALL, EXCEPT and INTERSECT get a line of their own between the two queries.
INSERT
INSERT INTO, the table name and the column list stay on one line. VALUES starts a new line, and each row in brackets goes on its own line below it, which makes long seed scripts easy to scan. With INSERT … SELECT, the query after the first line gets the normal SELECT layout.
UPDATE and DELETE
UPDATE and the table name share a line, SET starts the next one, and each assignment after SET gets its own line. DELETE FROM keeps the table name on the same line, and WHERE follows below as usual, so the filter that limits the change is easy to check before you run it.
WITH (CTEs)
WITH starts the statement, each CTE name and AS ( sit one step in, and the query inside the brackets is indented one more step. After the last closing bracket, the main query starts back at the left edge, so you can see where the helpers end and the real query begins.
Window functions
OVER (PARTITION BY … ORDER BY …) stays inline with its function, because the brackets keep it together. With UPPER keywords, ROW_NUMBER(, RANK(, LAG( and LEAD( are capitalised like other common functions.
CREATE, ALTER and DROP
Table statements start on their own line, and the column definitions stay together inside their brackets. Short definitions stay compact; for a long CREATE TABLE, expect a single long line inside the brackets rather than one column per line.
Every setting explained
| Setting | Choices | What it does |
|---|---|---|
| Mode | Format (beautify), Minify (one line) | A readable layout with line breaks, or the whole script on one line |
| Dialect | Standard SQL, MySQL / MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle (PL/SQL), SQLite, BigQuery | Which quotes, comments and escapes are recognised |
| Keyword case | UPPER, lower, Keep as typed | The case of SQL keywords only; names, text and numbers never change |
| Indent | 2 spaces, 4 spaces, Tab | The size of each indent step |
| Commas | At line end, At line start | Where the comma goes in lists split over several lines |
| AND / OR on their own lines | On or off | Starts each AND and OR in WHERE, HAVING and join conditions on a new line |
| Keep comments | On or off | Keeps -- , # and /* */ comments, or removes them |
| Empty lines between statements | 0, 1, 2 | Blank lines after each semicolon |
Indent: two spaces is compact and common in application code, four spaces matches many style guides, and Tab lets each editor show the indent at its own width. The choice only affects the start of lines; spaces inside a line are always single.
Commas: At line end is the familiar style. At line start puts the comma at the front of the next line, as in , u.name, which makes it easy to comment out or add the last column without touching the line above. It applies to SELECT lists, GROUP BY, ORDER BY, SET, RETURNING, PARTITION BY and WITH lists. Rows after VALUES always go one per line with the comma at the end.
AND / OR on their own lines: when it is on, each AND or OR in a WHERE, HAVING or join condition starts a new line one step in. The AND inside BETWEEN … AND … stays on the same line, and conditions inside a CASE expression are not split. Conditions inside ordinary brackets, such as (a = 1 OR b = 2), also stay together, which keeps the grouping visible. Turn the option off to keep short conditions on one line.
Keep comments: on by default. Line comments (-- and, in MySQL, #) end their line, so a new line starts after them; block comments /* */ stay inline where you wrote them. Turn the option off to strip all comments, for example before pasting SQL into a ticket.
Choosing the dialect, and why it matters
The dialect setting changes how the tokenizer reads your text, not how the layout looks. It decides which characters start a quoted name, which start a string, and whether # begins a comment. If the dialect is wrong, the most common symptom is a red error about a quote that is never closed, or a quoted name that gets split into pieces.
When you are not sure, choose the database the query runs on. Standard SQL suits portable queries and most textbook examples. The sections below cover the details for each database.
| Dialect | Quoted names | Strings | Extra rules |
|---|---|---|---|
| Standard SQL | "double quotes" | 'single quotes' | -- and /* */ comments; '' for a quote inside text |
| MySQL / MariaDB | `backticks` | 'single' or "double" quotes | # comments; backslash escapes in strings |
| PostgreSQL | "double quotes" | 'single', E'…' and $$ blocks | :: casts kept tight; $tag$ quoting |
| SQL Server (T-SQL) | [brackets] or "double" | 'single', N'unicode' | @variables kept; CROSS / OUTER APPLY laid out as joins |
| Oracle (PL/SQL) | "double quotes" | 'single quotes' | :bind variables kept |
| SQLite | "double", `backticks`, [brackets] | 'single quotes' | All three name styles recognised |
| BigQuery | `backticks` | 'single' with backslash escapes | QUALIFY clause; project.dataset.table paths |
SQL formatter for MySQL and MariaDB
Choose MySQL / MariaDB in the Dialect list and the tokenizer follows MySQL's rules. Backticks quote names, so `order`, `group` or `user name` are kept exactly, even when the name is also a keyword. Both single and double quotes start strings, as MySQL treats them by default, and a backslash inside a string escapes the next character, so 'it\'s' does not end early.
A # starts a line comment, alongside -- and /* */. In other dialects # is just an operator, which is why the right dialect matters for MySQL scripts exported from tools that write # comments.
MySQL-specific clauses get a sensible layout too: ON DUPLICATE KEY UPDATE starts its own line with each assignment below it, and LIMIT with an offset, such as LIMIT 20, 10, stays together. A sql formatter for mysql that knows these rules can tidy dump files, saved queries and slow-query log entries without breaking a single string.
SQL formatter for PostgreSQL: $$ blocks, :: casts and CTEs
Pick PostgreSQL and the formatter understands the parts of Postgres syntax that trip up simpler tools. Dollar-quoted blocks, $$ … $$ or $body$ … $body$, are read as one string, so a function body written inside them is kept exactly, line breaks and all. Casts written with :: stay tight to the value, so price::numeric and created_at::date are not split apart.
Double quotes mark names, as Postgres expects, so "userId" keeps its capital letter. E'…' strings allow backslash escapes, and positional parameters such as $1 and $2 are kept as written. JSON operators like ->, ->>, #> and @> are recognised as single operators and get a space on each side.
RETURNING, ON CONFLICT, WINDOW and FILTER (WHERE …) are known, and a sql formatter for postgresql that keeps WITH queries readable is useful for long reports: each CTE name and its bracketed query are laid out as their own block, with the final SELECT back at the left edge.
SQL formatter for SQL Server (T-SQL)
Choose SQL Server (T-SQL) and square brackets become quoted names, so [Order Details], [dbo].[Customers] and other names with spaces are kept whole. N'…' Unicode strings and @variables are kept exactly as written.
Keywords such as TOP, MERGE and WHEN MATCHED are known, and CROSS APPLY and OUTER APPLY are laid out like joins, each on its own line with the same indent as JOIN.
A sql formatter for sql server is handy for queries copied from execution plans, traces or application logs, where the text often arrives on one line with brackets around every name. Stored procedure bodies are kept token for token, though their layout stays simple: the formatter focuses on queries rather than control-of-flow statements like IF and WHILE.
SQL formatter Oracle guide: bind variables, quoting and PL/SQL
Oracle SQL follows the standard quoting rules: single quotes for text, with two single quotes for a quote inside it, and double quotes for case-sensitive names such as "OrderTotal". Choosing Oracle (PL/SQL) keeps those rules, and bind variables such as :customer_id are kept exactly as written.
FETCH FIRST 10 ROWS ONLY starts its own line, like LIMIT does in other databases, and NVL(, TO_CHAR( and TO_DATE( are capitalised as functions when Keyword case is UPPER.
Two honest limits: Oracle's alternative quoting, q'[ … ]', is not recognised, so write such strings with doubled quotes before formatting. And PL/SQL blocks (DECLARE, BEGIN, END) are kept token for token but not given a full block layout. As a sql formatter oracle teams can use for everyday SELECT, INSERT, UPDATE, MERGE and DELETE statements, it does the job well.
SQLite and BigQuery
SQLite accepts three ways of quoting names: double quotes, backticks and square brackets. Choose SQLite and all three are recognised, which matters for schemas created by different tools over the years. PRAGMA, VACUUM and other SQLite words are known keywords and follow your Keyword case setting.
BigQuery uses backticks around full table paths such as `my-project.sales.orders`, and the hyphen inside them is safe because the whole path is one quoted name. Strings accept backslash escapes, and QUALIFY, WINDOW, STRUCT and ARRAY are known. QUALIFY starts its own line, so filters on window functions are easy to find.
SQL formatter in single line: Minify mode
Sometimes you need the opposite of pretty: a query that fits on one line inside a string in your code, a config value, a shell command or a CSV cell. Switch Mode to Minify (one line) and you get a sql formatter in single line form: every line break and repeated space is removed, and a space is kept only where two words would otherwise run together.
The result is as short as it can safely be. A space stays between two words, between a number and a keyword, and before a quoted string, but not around commas, brackets or operators. The formatted example above, minified, reads:
SELECT u.id,u.name,CASE WHEN o.total>100 THEN 'big' ELSE 'small' END AS size FROM users u JOIN orders o ON o.user_id=u.id WHERE o.id IN(SELECT order_id FROM refunds WHERE amount>0)AND u.active=1 LIMIT 10;Minify does not change letter case; it keeps every word as it appears in the input. If you want capitals on one line, format with UPPER keywords first, paste that result back into Your SQL and then minify it.
SQL minifier online: comments and safe spacing
As a sql minifier online, the Minify mode has one extra choice: Keep comments. When it is off, every comment is removed. When it is on, comments are kept, and line comments are rewritten as block comments, so -- active only becomes /*active only */. That matters because a -- comment on a single line would swallow everything after it.
The minifier is also careful in two quiet places. A minus followed by a negative number, as in a - -1, keeps its space so it does not turn into the start of a -- comment, and a / followed by * keeps its space for the same reason. Strings, quoted names and numbers are copied exactly, just like in format mode.
Minify is useful for logging, for storing queries in one-line config values and for comparing two queries without whitespace getting in the way. To compare formatted versions line by line, the Diff Checker works better.
SQL formatter and validator: what the checks catch, and what they do not
Every time the text changes, the tokenizer reads it from start to end, and that reading doubles as a quick check. If something is never closed, the output box is replaced by a red message that names the line and the column where the problem starts, for example Line 4, column 12: This text in quotes is never closed.
- A string with no closing quote: This text in quotes is never closed.
- A quoted name with no closing ", ` or ]: This quoted name is never closed with the matching character.
- A block comment with no end: This comment is never closed with */.
- A bracket that is opened and never closed, or closed without being opened: This ( is never closed, or This ) has no matching (.
- In PostgreSQL, a $$ or $tag$ block with no end: This $$ quoted block is never closed.
That is the full list. This sql formatter and validator does not connect to a database, so it cannot know whether a table or column exists, whether you have permission or whether types match. It also does not check the full SQL grammar: a misspelled keyword, a missing comma between columns or a WHERE before FROM will be formatted, not reported. Run the query against a test database, or use EXPLAIN, to catch those.
Even so, the checks catch the most common copy-and-paste mistakes, a quote lost when a query was cut from a log or a bracket missing at the end of a long subquery, and they tell you exactly where to look.
What people use it for
Reading log and debug output
Queries printed by frameworks and slow-query logs arrive on one line. Paste them in to see the joins and filters at a glance.
Code reviews
Format before committing so diffs show real changes, not spacing. Agree on the settings once and everyone gets the same layout.
Migrations and seed scripts
Tidy SELECT, INSERT, UPDATE and DELETE statements before they go into version control. Column lists in CREATE TABLE and INSERT INTO stay on one line.
Learning SQL
Seeing each clause on its own line makes the order of SELECT, FROM, WHERE, GROUP BY, HAVING and ORDER BY easy to learn.
Documentation and tickets
Readable SQL in a wiki page or bug report saves the next person time. Turn off Keep comments to share only the query.
Embedding SQL in code
Use Minify to get one line for a string constant, then paste it into your code or config file.
Troubleshooting: when the output looks wrong
Red message: text in quotes is never closed
Check the line and column shown. A common cause is a quote inside text written as \' in a dialect without backslash escapes; choose MySQL / MariaDB or BigQuery, or write the quote twice ('').
Backtick names look broken
In Standard SQL, PostgreSQL, SQL Server and Oracle a backtick is not a quote, so a name like `order` can be read as the keyword ORDER. Choose MySQL / MariaDB, SQLite or BigQuery.
A # comment ran into the query
# starts a comment only in MySQL / MariaDB. In other dialects it is read as an operator. Switch the dialect, or write the comment with -- instead.
[Brackets] split into pieces
Square-bracket names are recognised only in SQL Server (T-SQL) and SQLite. Pick one of those in the Dialect list.
A column name became uppercase
Words that are also keywords, such as range, first or key, are capitalised with UPPER unless they come after a dot, as in t.range. Quote the name, or choose Keep as typed.
The output is one long line
Mode is set to Minify (one line). Switch it back to Format (beautify) to get line breaks and indents.
Most settings are missing
In Minify mode only Keep comments is shown; keyword case, indent, commas and the line options apply to format mode.
Copy does not work
Some browsers block the clipboard in private windows. Click in the output box, select all with Ctrl+A or Cmd+A and copy by hand, or use Download .sql.
Tips for readable SQL
- Agree on one style for the team: keyword case, indent and comma position. The page remembers your choices, so you only set them once.
- Give tables short, meaningful aliases, such as c for customers and o for orders, and use them on every column once a query has a join.
- Keep AND / OR on their own lines, and wrap mixed AND and OR conditions in brackets so the order of evaluation is clear.
- Keep comments that explain why, such as a business rule, and remove ones that only repeat what the SQL already says.
- Format generated SQL before you paste it into a review, so reviewers read structure instead of one long line.
- When a query fails, format it first: a missing join condition or a misplaced bracket is much easier to spot.
Is it safe? Formatted in your browser, never run
This formatter is code that runs inside this page. Your queries are not uploaded, not logged and not sent to any database, and they are never executed. The page has no database connection at all, so nothing can read, change or delete your data.
Only your settings, such as the dialect, keyword case, indent and comma style, are stored in this browser's local storage. The SQL itself is not saved. That matters with real data: queries often contain customer names, emails or IDs in their WHERE clauses, and a page that never uploads is a safe place to format them.
Related developer tools
Working with API responses next to your queries? The JSON Formatter makes JSON readable and checks it, and CSV to JSON turns exported query results into JSON for an API or a test fixture. The Regex Tester helps when you build LIKE patterns or REGEXP filters and want to try the pattern first.
To review a change to a long query, format both versions with the same settings and paste them into the Diff Checker. With the whitespace made consistent, only the real changes show up.
Frequently asked questions
What is the quickest way to use a sql formatter online?
Paste your query into Your SQL at the top of this page. The formatted version appears on the right as you type, and Copy puts it on your clipboard. There is nothing to install and no button to press.
Is this sql formatter free?
Yes. There is no account, no limit on the number or length of queries, and no paid version. It runs in your browser, so there is nothing to pay for.
What is the difference between a SQL formatter and beautifier?
They are two names for the same job: laying SQL out with line breaks and indentation so it is easy to read. Here, Format (beautify) is the mode that does it, and Minify (one line) does the reverse.
Does it work as a sql formatter for mysql?
Yes. Choose MySQL / MariaDB in the Dialect list. Backtick names, # comments, double-quoted strings and backslash escapes are then read correctly, and ON DUPLICATE KEY UPDATE gets its own line.
Can I use it as a sql formatter for postgresql?
Yes. Choose PostgreSQL. Dollar-quoted $$ blocks are kept whole, :: casts stay attached to the value, double quotes mark names, and $1 parameters are kept as written.
Is there a sql formatter for sql server names in [brackets]?
Choose SQL Server (T-SQL). Square-bracket names such as [Order Details] are then treated as one quoted name, and N'…' strings and @variables are kept exactly.
Does the sql formatter oracle mode handle bind variables?
Yes. Bind variables such as :id are kept as written, and NVL, TO_CHAR and TO_DATE are capitalised with UPPER keywords. Oracle's q'[…]' alternative quoting is not recognised, and PL/SQL blocks get only a simple layout.
How do I get sql formatter in single line output?
Switch Mode to Minify (one line). Line breaks and extra spaces are removed, with a single space kept only where two words would otherwise join. Strings and names are not changed.
Is it a sql formatter and validator in one?
Partly. It reports unclosed quotes, quoted names, comments and brackets with the line and column. It does not check table or column names or the full SQL grammar, because it never connects to a database.
What does the sql minifier online option do with comments?
With Keep comments off, comments are removed. With it on, they are kept, and -- or # line comments are turned into /* */ block comments so they cannot hide the rest of the one-line query.
Will formatting change what my query does?
No. Only spaces, line breaks and, if you choose, the case of keywords change. Text in quotes, quoted names, numbers and comments are copied exactly, and nothing is added, removed or reordered.
Is my SQL uploaded or run?
No. Formatting happens in your browser and the page has no database connection. Your queries are not uploaded, logged or executed. Only your settings are remembered in this browser.
Which dialects are supported?
Standard SQL, MySQL / MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle (PL/SQL), SQLite and BigQuery. The dialect decides which quotes, comments and escapes are recognised.
Why does it say a quote is never closed when my query works?
Usually the dialect does not match. A \' escape is read as an escape only in MySQL / MariaDB and BigQuery, and backticks are names only in MySQL, SQLite and BigQuery. Choose the dialect your database uses.
Can I put commas at the start of lines?
Yes. Under Indent and commas, choose At line start. Lists in SELECT, GROUP BY, ORDER BY, SET and WITH then begin each line after the first with a comma.
Can I indent with tabs?
Yes. Choose Tab under Indent, or pick 2 or 4 spaces. The choice only affects the start of each line; spaces inside a line stay single.
Can it format several statements at once?
Yes. Each semicolon ends a statement, the counter shows how many were found, and Empty lines between statements adds 0, 1 or 2 blank lines between them.
Can I keep my keywords in lowercase?
Yes. Set Keyword case to lower, or to Keep as typed to leave every word as you wrote it. Names, text and numbers never change case with any setting.
How do I format a .sql file?
Press Open .sql file and choose a .sql or .txt file. The text is loaded into the box and formatted at once. Download .sql saves the result as formatted.sql, or as minified.sql in Minify mode.
Does it format CREATE TABLE column lists?
Column lists in CREATE TABLE and INSERT INTO stay on one line inside their brackets. Rows after VALUES go one per line, and SELECT, UPDATE and DELETE statements get the full clause layout.
Are my settings saved?
Yes, in this browser's local storage: mode, dialect, keyword case, indent, commas, the line options and Keep comments. The SQL you type is never stored.
Format your SQL now
Seven dialects, keyword case, indent and comma styles, one-line minify and checks for unclosed quotes. Free, private and never run.
Back to the toolLast updated October 2026 · Written and maintained by the FlipMyFormat team