SQL Formatter Online

Pretty-print SQL queries with consistent indentation and keyword case for MySQL, PostgreSQL, SQL Server, Oracle, BigQuery and more, or compact them.

Free tool: 20 requests per minute.

Result

Press “Run” to see the result.

The SQL formatter rewrites a query with one clause per line, indented column lists and joins, and a consistent case for keywords, data types and functions (keyword_case upper, lower or preserve). Choose the dialect so its syntax is understood: mysql, mariadb, postgresql, sqlite, tsql (SQL Server), plsql (Oracle), bigquery, snowflake, redshift, spark, db2, trino, clickhouse or standard sql.

Tune the layout with indent (1–8 spaces) or tabs=true, expression_width (how long a parenthesised expression may stay on one line), logical_operator_newline (before or after AND / OR) and lines_between_queries for scripts with several statements. String literals and comments are kept.

minify=true does the opposite: comments are removed and whitespace outside quotes collapsed, for logs or query strings. A query that cannot be parsed returns invalid_sql with the position of the problem.

Use this in your code

curl -X POST "https://apibox.io.vn/v1/sql-format" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"sql":"select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.city = '\''Hà Nội'\'' and o.total > 100000 group by u.id, u.name order by orders desc limit 10","dialect":"postgresql"}'

API documentation → Get a free API key

FAQ

Does it check that my SQL is valid?

Only its syntax as far as formatting needs; table and column names are not checked against a database.

Are comments kept?

Yes when formatting. minify=true removes them.

Which dialect should I choose?

The one of your database; it matters for quoting (backticks, [brackets]) and specific keywords. sql works for standard queries.