SQL Beautifier
Format or minify SQL for MySQL, PostgreSQL, SQL Server, Oracle, SQLite, BigQuery and more.
SQL Beautifier
SQL Beautifier turns a long, one-line query into readable SQL: each clause on its own line, columns and conditions indented, and keywords in a consistent case. Choose your database's dialect so its own syntax is understood, pick upper or lower case keywords and the indent you use, and copy the result. The Minify button does the opposite and packs a query onto one line. Your SQL is formatted in your browser and never sent anywhere.
How to format SQL
- Paste your query into the editor (a sample query is there to try first).
- Choose the SQL dialect, for example MySQL, PostgreSQL or SQL Server (T-SQL).
- Choose Keywords (UPPER CASE, lower case or as written) and the Indent (2 or 4 spaces, or a tab).
- Click Beautify SQL, then Copy.
Supported dialects
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Amazon Redshift, IBM Db2, Spark SQL, Trino / Presto, DuckDB and ClickHouse. Picking the right one matters for syntax that only some databases have, such as backtick-quoted names in MySQL, :: casts in PostgreSQL, square-bracket names in SQL Server or $$ blocks in PL/pgSQL. If formatting fails, the tool tells you where it stopped, which usually means a typo or the wrong dialect.
Formatting and minifying
- Beautify for code reviews, documentation, debugging and pull requests: one clause per line makes joins, filters and grouping easy to follow.
- Minify to put a query on one line for a config file, a log search or a string in code. It removes comments and extra spaces but keeps text inside quotes exactly as it is, so
'a -- b'stays intact.
Both only change whitespace, line breaks, comments (Minify) and keyword case. Table names, values and the logic of the query are not touched.
When it comes in handy
- Reading queries copied from application logs, ORMs and query analyzers, which print SQL on one line.
- Making SQL consistent before committing it or pasting it into documentation.
- Understanding a complex query with many joins and subqueries.
For other code, use the JSON Beautifier, the HTML Formatter or the CSS Formatter.
Frequently asked questions
Does formatting change what the query does?
Is my SQL sent to your server?
Can it format several statements at once?
Does it check my SQL for errors?
Related guides
-
Schema Markup for Beginners: What JSON-LD Does and Which Types to Use
A beginner-friendly explanation of structured data and JSON-LD, the schema types most sites need, and how to add and test them.
-
301 vs 302 Redirects: Which One to Use, and How to Check Them
The difference between permanent and temporary redirects, how each affects SEO, common redirect mistakes, and how to set up and test them.
-
How to Write Title Tags and Meta Descriptions That Get Clicks
What title tags and meta descriptions are for, how long they can be, and a simple method for writing ones that people actually click.