SQL Formatter
Format and minify SQL for PostgreSQL, MySQL, SQL Server and generic SQL. Queries are never executed.
Input
Output
How to use the SQL Formatter
- Paste a query, or click Sample.
- Choose your database's dialect so its syntax is understood.
- Pick keyword case and indentation. The formatted SQL appears instantly.
- Use Minify to put a query on one line, for example to paste it into code or a log search.
Supported databases
PostgreSQL, MySQL, MariaDB, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Amazon Redshift, Spark SQL, IBM Db2, Trino/Presto, DuckDB and standard SQL. Each dialect understands its own quoting: [brackets] in SQL Server, backticks in MySQL, $$ function bodies and $1 parameters in PostgreSQL.
A minifier that doesn't break queries
- Strings and quoted identifiers are never changed, including doubled quotes and MySQL backslash escapes.
- Optimizer hints such as
/*+ INDEX(t idx) */and MySQL's/*! ... */are kept. They change how the query runs, so removing them would change behavior. - Regular comments are removed, so a query can safely become a single line.
Frequently asked questions
Is my SQL sent anywhere?
No. Formatting runs entirely in your browser. Queries are never executed, uploaded or stored.
Does it check that my SQL is correct?
No. It understands SQL well enough to lay it out, and reports problems like unterminated strings or missing parentheses. It doesn't know your tables or columns, so a query can format nicely and still fail on your database.
Why do I get a parse error for valid SQL?
Usually the dialect doesn't match. Syntax like [name], backticks or ::type casts only exists in some databases. Choose your database in Dialect and try again.
Related tools
All tools- JSON FormatterFormat, validate and minify JSON with syntax highlighting and precise error locations.
- XML FormatterFormat, validate and minify XML with syntax highlighting, entirely in your browser.
- Diff CheckerCompare two texts side by side or as a unified diff, with added, removed and changed lines.
- Regex TesterTest regular expressions with live match highlighting, capture groups, flags and explanations.
- Cron Expression GeneratorBuild Linux cron expressions with a visual editor and preview the next run times.