Skip to content

SQL Formatter

Format and beautify SQL with dialect-aware indentation and keyword case for PostgreSQL, MySQL, SQLite, SQL Server and more. Runs in your browser.

Processed locally in your browser. Your data never leaves your device.

About this SQL formatter

Long one-line queries are hard to read and review. This tool re-lays out SQL with one clause per line, indented lists and consistent keyword case, using dialect-aware rules for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, BigQuery, Snowflake and more. It runs in your browser, so queries containing real table names or data stay private.

How to use it

  1. Choose your database dialect.
  2. Paste your SQL. It is formatted as you type.
  3. Adjust the indent (2 spaces, 4 spaces or a tab) and keyword case.
  4. Copy or download the result.

Example

select id,name from users where active=1 order by name becomes a query with SELECT, FROM, WHERE and ORDER BY each on their own line and the column list indented beneath SELECT.

What is preserved

  • Comments (-- line and /* block */) stay where they are.
  • Strings and quoted identifiers are never altered, including escaped quotes and dollar-quoted PostgreSQL strings.
  • Statements separated by semicolons are each formatted and separated by a blank line.

Frequently asked questions

Does formatting change what my query does?
No. Formatting only changes whitespace and, if you choose, the case of keywords. Strings, quoted identifiers, numbers and comments are left as written. Text inside a multi-line block comment may be re-indented.
Which dialect should I choose?
Pick the database you run the query on. Dialects differ in quoting (backticks in MySQL, square brackets in SQL Server, dollar-quoted strings in PostgreSQL), operators and keywords. Standard SQL is a good default when unsure.
Why do I get a parse error?
The formatter needs to understand the statement to indent it. Common causes are an unclosed parenthesis or quote, a missing comma, or syntax from a different dialect. The message gives the line and column, and Go to selects it.
Can it minify SQL?
Not here. Safely removing whitespace needs a full understanding of comments and string literals in every dialect, and a wrong guess could change a query, so this tool only formats.
Is my query sent to a server?
No. Formatting runs in your browser, in a background worker for large scripts. Nothing you paste is uploaded, stored or logged, which matters when a query contains table names or literal data.