SQL Formatter and Minifier

Format or minify SQL for PostgreSQL, MySQL, MariaDB, SQLite, T-SQL, PL/SQL and BigQuery. Set keyword case, indent and commas. Runs in your browser.

Runs in your browser. Nothing is uploaded.

Web

SQL Formatter

SQL

How placeholders such as ?, $1, :name, @name and double braces are recognised

Result

Paste SQL on the left, or load the sample. Pick the dialect that matches your database for the best result.

Example

Input
select id,name from users where active=1 and age>30 order by name
Result
SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
  AND age > 30
ORDER BY
  name

Format, then read

Paste a query and it is laid out with each clause on its own line, one column per line, conditions indented and keywords in the case you choose. That makes a 400-character one-liner from an ORM log or a slow-query report readable enough to review. Formatting uses the open-source sql-formatter library, run in your browser, and the same input always gives the same output, so it is also useful for tidying SQL before you commit it.

Choose the dialect that matches your database: PostgreSQL, MySQL, MariaDB, SQLite, T-SQL for SQL Server, PL/SQL for Oracle, BigQuery or standard SQL. Dialects differ in quoting ([name] in T-SQL, backticks in MySQL), in operators such as PostgreSQL's ->> and in reserved words, so the wrong dialect can give a parse error or odd breaks.

Options that matter

Keywords can be upper case, lower case or left as typed. Indent is two or four spaces or a tab. Commas can end the line or start the next one, a style some teams use so a diff of an added column touches one line. You can also put AND and OR at the start or end of the line and choose how many blank lines separate statements.

Query parameters keep their form. Pick how placeholders are written (?, $1, :name, @name or double braces) so the formatter treats them as one token instead of splitting them; the dialect default is usually right. Minify does the reverse: it collapses whitespace and removes comments, leaving strings, quoted identifiers, PostgreSQL dollar-quoted text and MySQL optimizer hints untouched.

What formatting does not do

A formatter changes layout only. It does not check that tables, columns or functions exist, does not validate semantics, and never runs your query, so a formatted query can still fail in the database. If the tool cannot parse the text it reports the line and column of the problem and suggests trying another dialect instead of guessing.

Be careful with minified output when a line comment is the last thing in the text; this tool removes comments so that cannot happen, but if you minify by hand, a -- comment will swallow everything after it on the same line. Review diffs after reformatting a large file, since whitespace changes can hide real edits.

Frequently asked questions

Does it validate my SQL?

No. It only formats. It will reject text it cannot tokenise, but it does not know your schema, so a well-formatted query may still be wrong. Run it against a test database to find out.

Which dialect should I pick?

The one that matches the database running the query. If the text came from a tool such as a query log, check which database produced it. Standard SQL is a safe fallback for simple statements.

Why is my parameter placeholder split apart?

Placeholder syntax varies. Set the placeholder style to match yours, for example $1 for PostgreSQL drivers or ? for MySQL, so the formatter keeps it as one token.

Does minify change what my query does?

It removes comments and extra whitespace and keeps string contents exactly, so the statement is equivalent. MySQL optimizer hints and conditional comments are kept because they change behaviour.

Is my SQL uploaded?

No. Formatting happens in your browser. Queries often contain table names and values you may not want to share, and none of it leaves the page.

Related tools