SQL Formatter
Paste SQL and get a readable, formatted version. Choose from 12 dialects: PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), BigQuery, Snowflake, Oracle (PL/SQL), Redshift, Trino, Spark and standard SQL. You can change keyword case, indentation (2, 4 or tab), whether AND / OR go at the start or end of a line, and the width that fits on one line. dbt, Jinja and shell template variables, SQL Server GO and MySQL DELIMITER are handled without breaking them. It suits reading long one-line SQL from logs and matching style before code review. It only formats; it does not run the SQL or check that it is correct. Everything runs in your browser and your SQL is never sent anywhere. It also runs a quick check for common mistakes: DELETE or UPDATE without WHERE, DROP and TRUNCATE, = NULL, NOT IN with a subquery, SELECT *, comma joins, LIMIT without ORDER BY and a leading % in LIKE.
SQL check
What this SQL does
A quick lexical read of the SQL above: statement types, the tables it touches, joins and CTEs. Strings and comments are ignored.
Fill in parameters
Replace ?, $1, :name and @name with values, for example to run a query copied from a log. Numbers, NULL and TRUE/FALSE stay bare; other values are quoted.
No placeholders (?, $1, :name, @name) found in the SQL above.
Clean up and embed
Works on the SQL in the box above. Strip comments, switch identifier quotes between MySQL, PostgreSQL and SQL Server styles, wrap the SQL as a string for your code, or pull the SQL out of a code string or log line.
Convert to another database (dialect)
Rewrites the SQL in the box above from one database to another (MySQL, PostgreSQL, SQLite, SQL Server): quotes, LIMIT / TOP, IFNULL / COALESCE, NOW(), GROUP_CONCAT / STRING_AGG, :: casts and common CREATE TABLE types. Anything it cannot fix safely is listed below. The result is a starting point: always test it on the real database.
Check by hand
GuideHow to use & features
- Select your database engine from the "Dialect" dropdown (defaults to MySQL).
- Paste your SQL query into the input field to see the formatted output instantly.
- Click the "Copy" button to grab the beautified query for your code or logs.
SamplesSample input & output
Formatting a SELECT statement
select a,b,c from table1 join table2 on table1.id = table2.id where a > 10 order by b desc
SELECT a, b, c FROM table1 JOIN table2 ON table1.id = table2.id WHERE a > 10 ORDER BY b DESC
FAQFAQ
Which SQL dialects are supported?
It supports major dialects such as MySQL, PostgreSQL, and SQLite, applying sensible indentation and keyword capitalization. When your query uses dialect-specific syntax, choosing the matching dialect yields a more natural formatting result.Does formatting change the meaning or results of the query?
No. Formatting only adjusts appearance — whitespace, line breaks, and indentation — and does not affect the query’s syntax or results. You can safely paste a production query and improve only its readability.Can it format a long single-line SQL pulled from logs?
Yes. Paste a long query that your app logged on one line, and it reformats into a readable shape with line breaks and indentation per clause (SELECT / FROM / WHERE, etc.). Helpful for tidying before review and for grasping complex JOIN structures.Can it format scripts with GO or DELIMITER lines?
Yes. In T-SQL, GO and GO 5 lines are kept as batch separators and the statements around them are formatted separately. MySQL DELIMITER lines are handled the same way, so a procedure delimiter such as // is not broken. A line that only says go inside a string or comment is not treated as a separator.Can I change the indentation and keyword case?
Yes. You can pick the indent (2 spaces, 4 spaces or a tab), keyword case (keep, upper or lower), whether AND / OR goes at the start or end of a line, and the width at which an expression is kept on one line. Your dialect and options are remembered for next time.Can I convert MySQL SQL for PostgreSQL or SQL Server?
Yes for the mechanical parts: quotes, LIMIT, IFNULL / COALESCE, NOW(), GROUP_CONCAT / STRING_AGG, :: casts, and CREATE TABLE types and AUTO_INCREMENT. Things whose meaning changes, such as ILIKE, ||, upserts and RETURNING, are not rewritten; they are listed as items to check by hand. The result is not guaranteed to behave identically, so test it on the real database before running it.
Use casesCommon use cases
Making one-line SQL from logs readable
Paste a long SQL statement from application or slow-query logs and it is split into clauses with line breaks and indentation. JOIN conditions and WHERE filters become easy to follow, which speeds up finding why a query is slow.Matching SQL style before code review
Choose keyword case, indent width (2, 4 or tab) and whether AND / OR go at the start or end of a line. Format to your team style before pasting into a pull request and avoid style-only review rounds.Formatting SQL with dbt, Jinja or shell variables
Template variables such as `{{ ref('orders') }}`, `{% if … %}` and `${table}` are treated as single tokens. The SQL is formatted without syntax errors, template included.Formatting for a specific database
Pick from 12 dialects including PostgreSQL, MySQL, SQLite, SQL Server, BigQuery and Snowflake. Placeholders such as `$1` and `@name` are preserved according to the dialect.
NotesNotes & limitations
It formats only; it does not check whether the SQL is correct
It does not run the query or check that tables and columns exist. SQL with syntax errors may fail to format, or may be split at unexpected places. Fix the syntax first, then format.A mismatched dialect can break the layout
Dialects have their own syntax, such as BigQuery arrays or the PostgreSQL `::` cast. If the output looks wrong, switch to the dialect of your database. Very vendor-specific syntax and procedural code inside stored procedures may not format perfectly.Template variables are kept, not interpreted
`{{ … }}`, `{% … %}` and `${…}` are preserved as a single unit. When a template changes the structure of the SQL, for example a statement branched by `{% if %}`, line breaks may not fall where you expect.Check the formatted SQL before running it
Keyword upper-casing applies to reserved words only and leaves string contents alone. Line breaks and indentation can, however, move the position of comments. Review the diff before running or deploying. Input is processed in your browser and is not sent to a server.
AboutAbout this tool
High-Performance SQL Formatter
Beautify and format unreadable, minified, or overly complex SQL queries extracted from applications and log files. This tool applies appropriate indentation, line breaks, and reserved keyword highlighting.
Supported Databases and Applications
It widely supports standard relational database dialects including MySQL, PostgreSQL, SQL Server, Oracle, and BigQuery.
Improving query readability is often the shortest path to discovering logic bugs, especially when tuning performance for massive SQL queries automatically generated by ORMs or during team code reviews.
Since everything runs client-side in your browser, your proprietary schema structures and queries never leave your device.
When to format SQL
- Before code review: Make complex queries easier for teammates to scan.
- While debugging ORM output: Reformat generated SQL from logs before checking joins and filters.
- During performance tuning: Add line breaks and indentation before investigating WHERE clauses, GROUP BY, and nested queries.
Practical note
Formatting improves readability, but it does not guarantee that a query is correct or fast. Always test the formatted SQL against the target database and review execution plans for performance-sensitive changes.
Articles for this tool
SQL Formatter: Making Queries Readable, and Why Dialect Selection Matters
Format messy SQL from logs or ORMs into readable queries. Why the dialect (PostgreSQL/MySQL/BigQuery) changes the output, and why formatting checks syntax.
How to Build SELECT and JOIN Queries Visually with a SQL Builder
Assemble SELECT, WHERE and JOIN clauses in your browser with a visual SQL builder. Useful for learning SQL, extracting data, and drafting queries before review.
SQL Clause Order Reference: Why WHERE Can't See Your SELECT Alias
SQL is written in one order and run in another. The logical execution order (FROM to LIMIT), why aliases fail in WHERE, and WHERE vs HAVING.
SQL JOIN Types: Complete Reference to INNER, LEFT, RIGHT & FULL
SQL JOIN types (INNER/LEFT/RIGHT/FULL/CROSS/SELF): syntax, a cheat sheet, why one-to-many joins duplicate rows, and the WHERE-vs-ON NULL trap.
