1. Home
  2. Spreadsheets & Data
  3. SQL Formatter

SQL Formatter

Format messy or one-line SQL queries with readable line breaks and indentation.

For every format and option in one place, use Code Formatter and Checker →

Runs in your browser · No upload

Loading the formatter…

Your query is processed in this browser only and is never uploaded.

How to use

  1. Paste SQL into the input | a one-line query from a log, ORM-generated SQL, or a script with several statements.
  2. Pick the SQL dialect of the database you run it on. Your choice is remembered for next time.
  3. Beautify breaks the query at each clause (SELECT, FROM, WHERE…) and indents it. You can change keyword case, indent width and where AND/OR go.
  4. Minify strips comments and extra whitespace so the query fits on one line in code or config.
  5. Copy the result or download it as a .sql file.

Why the dialect matters

The same characters mean different things in different databases, so the right dialect keeps your query intact while it’s reformatted.

Syntax Used by With the wrong dialect
`column` backtick identifiers MySQL, MariaDB, BigQuery Treated as unknown characters
[column] bracket identifiers SQL Server (T-SQL) Mistaken for array syntax
$1, ::text, $$ … $$ PostgreSQL Parameters and casts get split apart
# line comments MySQL, MariaDB Not a comment elsewhere
TOP 10, GO SQL Server A syntax error in standard SQL

Example

Beautifying select id, name from users where age > 20 and city = 'Boston' order by name; as MySQL with uppercase keywords and 2 spaces gives:

SELECT
  id,
  name
FROM
  users
WHERE
  age > 20
  AND city = 'Boston'
ORDER BY
  name;

Things to watch out for

  • Only whitespace and keyword case change. String values (‘Boston’) and table or column names are left alone, so query results don’t change. Major databases treat keywords case-insensitively.
  • Formatting is not validation. A formatted query isn’t guaranteed to run; the tool only reports a position when it can’t read the query at all, such as an unclosed bracket or quote.
  • Minify removes -- and /* */ comments but keeps MySQL’s /*! … */ (version-conditional code) and /*+ … */ (optimizer hints), because they change how the query runs.

FAQ

Is my query sent to a server?

No. Formatting runs in your browser with the open-source sql-formatter library, so queries containing table names or customer data never leave your machine.

Can I turn query results into a spreadsheet?

If your results come back as JSON, the JSON to CSV Converter produces a CSV that opens in Excel. To compare a query before and after an edit, use Text Diff.

Can't find the tool you need?

Tell us what you want to do. We build the most requested tools first.