Free SQL Formatter

Paste a query or a whole script and get it laid out one clause per line, with indented columns, joins, conditions, subqueries and CASE expressions, keywords in the case you choose, and syntax highlighting. Pick your database (MySQL, PostgreSQL, SQL Server, Oracle or SQLite) so quotes and comments are read correctly. Everything runs in your browser, so your SQL is never uploaded.

Formatting Options

Dialect decides how quotes and comments are read: 'strings', "identifiers", -- and /* */ comments; MySQL #, PostgreSQL $$ or [bracket] syntax asks you to pick a dialect.

1 line โ€ข 167 characters

Formatted Output

14 lines โ€ข 197 characters
SELECT
u.id,
u.name,
u.email,
o.order_id,
o.total
FROM
users u
INNER JOIN orders o ON u.id = o.user_id
WHERE
o.status = 'completed'
AND o.total > 100
ORDER BY
o.created_at DESC;

Formatting Features:

โœ“ One clause per line, indented content
โœ“ UPPERCASE, lowercase or preserved keywords
โœ“ 2 spaces, 4 spaces or tab indent
โœ“ Subqueries, CTEs and CASE indented
โœ“ Strings and comments never changed
โœ“ Multiple statements
โœ“ MySQL, PostgreSQL, SQL Server, Oracle, SQLite quoting and operators
โœ“ Syntax highlighting and line numbers
โœ“ Formats as you type

Tips:

  • โ€ข Only whitespace and keyword case change: the formatter re-reads its output with the chosen dialect's rules and shows your SQL unchanged if any token differs
  • โ€ข Pick your database as the dialect: it decides how quotes, comments, operators (PostgreSQL @@, <->, #-) and client commands (MySQL DELIMITER, psql \set, SQL*Plus SET / PROMPT / SPOOL and /, T-SQL GO and SQLCMD :setvar) are read. PostgreSQL COPY ... FROM stdin data rows are kept byte for byte. In Standard SQL mode, input with MySQL #, PostgreSQL $$ or [bracket] syntax is left unchanged with a prompt to pick the right dialect
  • โ€ข Semicolons inside strings and comments are handled correctly, so multi-statement scripts are safe
  • โ€ข Some databases (SQLite, for example) name an un-aliased result column after its exact text, so reformatting can change that label; give computed columns an AS alias if your code reads them by name
  • โ€ข All processing happens in your browser - your SQL is never uploaded

How to format SQL online, free and without uploading

To format SQL, paste your query into the SQL Input box (a sample is already loaded). The Formatted Output fills in as you type. Choose Indent (2 spaces, 4 spaces or Tab), Keywords (UPPERCASE, lowercase or Preserve) and Dialect, then click Copy Formatted, or Download .sql to save formatted-query.sql. The built-in sample, one 167-character line, becomes 14 lines with each column, join and condition on its own line. Show line numbers is switched on by default.

It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). The formatter is a script that ships with the page, and it never connects to a database. There is no account and nothing to install.

SQL formatting, or beautifying, changes only the layout of a query: line breaks, indentation and keyword case. The meaning stays the same, and this tool checks it by reading its own output again and falling back to your original text if any token differs. It does not validate your SQL. To go the other way and squeeze a query onto one line, use the SQL minifier.

Table of Use: what the formatter does to a query

SQL pasted in, the formatted result with the default 2-space indent and UPPERCASE keywords, and a note
SQL you pasteFormatted outputNote
select a,b from t where x=1SELECT a, b FROM t WHERE x = 1One clause per line, one column per line, spaces around operators
select id from users u join orders o on u.id=o.user_idSELECT id FROM users u JOIN orders o ON u.id = o.user_idJoins sit under FROM with the ON condition on the same line
select * from t where x in (select y from z)SELECT * FROM t WHERE x IN ( SELECT y FROM z )A subquery is indented one level deeper
with recent as (select id from orders) select * from recentWITH recent AS ( SELECT id FROM orders ) SELECT * FROM recentEach CTE is its own indented block
select case when total>100 then 'big' else 'small' end as size from ordersSELECT CASE WHEN total > 100 THEN 'big' ELSE 'small' END AS size FROM ordersWHEN and ELSE branches get their own lines
select a, -- first column b from tSELECT a, -- first column b FROM tA line comment stays at the end of its line, so b is not swallowed
select id from t where note='a;b'; select 2;SELECT id FROM t WHERE note = 'a;b'; SELECT 2;The ; inside the string is untouched; statements are split by a blank line
select [a] from t (Standard SQL)select [a] from tShown unchanged with a prompt to choose SQL Server (T-SQL) or SQLite

Features

  • Indent. 2 spaces, 4 spaces or Tab.
  • Keywords. UPPERCASE, lowercase or Preserve, which leaves each keyword exactly as you typed it.
  • Six dialects. Standard SQL, MySQL / MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle and SQLite, each with its own rules for quotes, comments and operators. A line under the options explains what the chosen dialect changes.
  • Never rewrites content. Strings, comments and quoted identifiers are copied exactly, and the output is re-checked against the input.
  • Scripts, not just queries. Many statements are split by a blank line, and client commands such as DELIMITER, GO, psql backslash commands and SQL*Plus lines stay on their own lines.
  • Warnings with line numbers. An unclosed quote or comment is reported, and a Switch dialect button appears when your SQL looks like another database.
  • Syntax highlighting and line numbers. Keywords, strings, comments, numbers and parameters are coloured, and Show line numbers can be turned off. Highlighting switches off above 3,000 output lines to keep the page responsive.
  • Line and character counts for the input and the output, plus Clear and Load Sample.

How to use the SQL formatter

  1. Paste your SQL into the SQL Input box, or click Load Sample. Click Clear to empty the box.
  2. Under Formatting Options, set Indent to 2 spaces, 4 spaces or Tab.
  3. Set Keywords to UPPERCASE, lowercase or Preserve.
  4. Pick your database under Dialect. If an amber message appears with a Switch dialect button, click it to use the dialect the formatter suggests.
  5. Read the Formatted Output. Untick Show line numbers if you do not want them.
  6. Click Copy Formatted, or Download .sql to save the file.

Who can use it

  • Backend developers reading a one-line query from an ORM log or a stack trace, and checking two versions in the text diff tool.
  • Data analysts tidying a long query before sharing it, after renaming a table everywhere with the find and replace tool.
  • Database administrators cleaning up scripts for MySQL, PostgreSQL, SQL Server, Oracle or SQLite before review, and making sample keys with the UUID generator or readable dates with the timestamp converter.
  • Students learning how joins, subqueries and CTEs nest, since every level gets its own indent.
  • Full-stack teams who also tidy other formats: the JSON formatter, the XML formatter, the JavaScript beautifier and the HTML beautifier.
  • Reviewers who need a keyword case that matches their style guide, with the text case converter for everything that is not SQL.

FAQs

How do I format SQL online?

Paste your query into the SQL Input box. The Formatted Output appears as you type, with one clause per line and indented columns, joins and conditions. Choose Indent, Keywords and Dialect above the boxes, then click Copy Formatted, or Download .sql to save formatted-query.sql. Click Load Sample to see an example first.

Will formatting change what my query does?

No, the query logic stays the same. Only whitespace, line breaks and, if you choose, keyword case change; strings, comments, quoted identifiers, operators and numbers are copied exactly. The formatter also re-reads its output and shows your SQL unchanged if any token differs. One caveat: SQLite names an un-aliased result column after its exact text, so give computed columns an AS alias.

Which SQL dialects does it support?

The Dialect list offers Standard SQL, MySQL / MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle and SQLite. The dialect decides how quotes, comments, operators and client commands are read, for example MySQL backticks and # comments, PostgreSQL $$ bodies and :: casts, T-SQL [brackets] and GO, or Oracle q'[...]' strings and bind variables.

Why does it say my SQL is shown unchanged?

In Standard SQL the formatter spots syntax that belongs to one database, such as a MySQL # comment, [bracket] identifiers or PostgreSQL $$ quoting. Reading it wrongly could swallow part of the query, so it leaves your text alone and offers a Switch dialect button. Click it, or pick the dialect yourself, and the query is formatted.

Can it format several statements at once?

Yes. Paste a whole script and each statement is formatted separately, with a blank line between them. Semicolons inside strings and comments do not split a statement. Client commands such as MySQL DELIMITER lines, T-SQL GO and psql backslash commands stay on their own lines exactly as you wrote them.

Does it check my SQL for errors?

Only for problems that affect reading the text: an unclosed quote or an unclosed /* comment produces a warning with a line number. It does not check table names, columns or grammar, and it never connects to a database. Run the formatted query in your own database client to confirm that it works.

Is my SQL sent to a server?

It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). The formatter is a script that ships with the page, so queries containing production table names or values stay on your device. There is no account and nothing to install.