- All tools
- SQL formatter
How do I format or minify SQL?
Paste your SQL, pick the dialect, indentation and keyword case, and press Format to get clean, indented SQL, or press Minify to squeeze it onto as few lines as possible. Formatting only changes whitespace and letter case; it does not check that the SQL is valid for your database or change what it does.
- Paste your SQL into the box, or keep the example.
- Choose the dialect, indentation and keyword case that match your database and style.
- Press Format or Minify, then copy the result.
What this page can do
- Format SQL in 12 dialects, including PostgreSQL, MySQL, SQL Server, BigQuery, Snowflake and Oracle PL/SQL
- Indent with 2 spaces, 4 spaces or tabs
- Keywords, data types and function names in upper case, lower case or as typed
- Minify that keeps strings, quoted names and comments safe, with an option to remove comments
- Syntax errors shown with the line and column
- Several statements at once, separated by semicolons
When to use this page
- Making a long query from a log or an ORM readable before you debug it.
- Tidying SQL before pasting it into a pull request, ticket or document.
- Shrinking a query to one line to fit in a config file, a shell command or a code string.
When to use something else
- You need to check that a query is valid or fast: run it against your database or use its EXPLAIN tool.
- You need a formatter that follows your team style rules in an editor: use a plugin or a tool such as sqlfluff in your project.
- Your SQL is mixed with template code such as Jinja or embedded in another language: the formatter may reject it.
How it compares with other options
Most editors and database clients, such as DBeaver, DataGrip and VS Code extensions, can format SQL, and they are the better choice if you format every day or want project-wide style rules. Online formatters are quicker for a one-off paste. This page uses the open-source sql-formatter library, so its layout follows that library’s rules and may differ from your editor’s; the dialect list is limited to what the library supports. Unlike many online formatters, it does the work in your browser, which matters when a query contains table names or values you would rather not paste into a website.
Where your text goes
Nowhere. Formatting and minifying are done by your own browser with code that loads together with the page. Nothing you paste is sent to a server, saved to an account or written to browser storage. You can check it yourself: open your browser’s network panel — the page still loads its own code and any ads, but no request carries your SQL.
Questions about this tool
Does formatting change what my query does?
No. Formatting only changes whitespace, line breaks and, if you choose, the letter case of keywords, data types and function names. String literals, quoted identifiers and comments are kept as written. The page does not run your SQL or connect to a database, and it cannot confirm that the query is valid for your database.
Why do I get a syntax error for SQL that works in my database?
The formatter has to understand the SQL to lay it out, and each dialect has its own keywords and quoting rules. Choose the dialect that matches your database first. Very new or vendor-specific syntax, and procedural code, may still be rejected even though the database accepts it. The message gives the line and column where the formatter gave up.
Does Minify change my SQL?
Minify removes extra spaces and line breaks outside strings, quoted names and comments. By default comments are kept, and a line break is kept after each -- comment so that the rest of the query does not become part of the comment. Tick Remove comments to delete them. Be careful with optimizer hints written as /*+ ... */ or MySQL /*! ... */ comments: they are comments to this page but can be instructions to your database, so keep comments if you use them.
Is my SQL saved or sent anywhere?
No. The formatting runs in your browser using a library that loads together with the page. Your SQL is not sent to a server or stored in your browser; closing or reloading the tab clears it, so copy the result somewhere safe first.