🗃️ SQL Formatter
Beautify and format SQL queries — MySQL, PostgreSQL, Oracle, Databricks and more.
Paste SQL on the left to see formatted output
Auto-formats as you type · 100% privateAbout SQL Formatter
SQL written in a hurry or generated by ORMs, query builders, or logging pipelines is often a single unreadable line or an inconsistently indented mess. This free online SQL formatter beautifies and standardises SQL queries across 8 major dialects — MySQL, PostgreSQL, Databricks, Oracle, SQL Server, BigQuery, Snowflake, and SQLite — all entirely in your browser with zero data sent to any server.
The formatter preserves your query's logic while applying consistent indentation, configurable keyword casing (UPPERCASE, lowercase, or Preserve), optional AND/OR placement at line beginnings, and proper alignment of SELECT columns, JOIN conditions, and WHERE clauses. It is especially useful when reading query plans, reviewing ORM-generated SQL, or preparing queries for documentation and pull request reviews.
How to format SQL
- Paste your SQL query into the left panel.
- Select the dialect that matches your database (MySQL, PostgreSQL, Databricks, etc.).
- Choose your preferred indent size (2 spaces, 4 spaces, or Tab) and keyword case (UPPER, lower, or Preserve).
- The formatted output appears instantly in the right panel with syntax highlighting.
- Click ⎘ Copy to copy the formatted query, or ⬇ Download to save it as a
.sqlfile.
Supported SQL dialects
🐬 MySQL & MariaDB
Full MySQL 8 syntax including window functions, CTEs, JSON functions, generated columns, and MariaDB-specific extensions.
🐘 PostgreSQL
Dollar-quoted strings, RETURNING, ON CONFLICT (upsert), LATERAL joins, and advanced window functions.
⚡ Databricks / Spark
Delta Lake syntax: CREATE OR REPLACE TABLE, USING DELTA, ZORDER BY, OPTIMIZE, LIQUID CLUSTERING, and Spark SQL functions.
🔶 Oracle PL/SQL
ROWNUM, CONNECT BY hierarchical queries, MERGE, DUAL, NVL, DECODE, and Oracle-specific date functions.
🪟 SQL Server T-SQL
TOP N, NOLOCK hints, CROSS APPLY, OUTER APPLY, FOR XML, FOR JSON, and T-SQL procedural constructs.
☁️ BigQuery
STRUCT and ARRAY types, UNNEST, QUALIFY, PARTITION BY date, and Google BigQuery date/time functions.
❄️ Snowflake
VARIANT, OBJECT_CONSTRUCT, ARRAY_AGG, QUALIFY, COPY INTO, FLATTEN, and Snowflake semi-structured data functions.
🎛️ Format options
Indent size (2/4 spaces or Tab), keyword case (UPPER/lower/Preserve), data type case, AND/OR at line start, and comma placement.
Frequently Asked Questions
Why should I format SQL before sharing it?
Formatted SQL is significantly easier to review, debug, and maintain. Consistent indentation makes JOIN conditions, subqueries, and WHERE clause logic immediately apparent. When opening a pull request that includes SQL changes, well-formatted queries reduce review time and catch logic errors that are invisible in minified form.
Does the formatter change the meaning of my query?
No — the formatter only changes whitespace, line breaks, and keyword casing. It never reorders clauses, modifies column order, or alters the logic of your query. The formatted output is semantically identical to the input.
Which dialect should I choose if I'm not sure?
For most standard SQL (SELECT, INSERT, UPDATE, DELETE, JOIN), any dialect will format correctly. The dialect setting mainly affects how dialect-specific keywords and functions are highlighted and normalised. Start with PostgreSQL or MySQL and switch if the formatter misinterprets a specific construct.
Can I format stored procedures and PL/SQL blocks?
Yes, for Oracle PL/SQL and SQL Server T-SQL, the formatter handles procedural blocks including BEGIN/END, DECLARE, IF/ELSE, LOOP, CURSOR, and EXCEPTION blocks. Select the matching dialect for best results.
Is my SQL data safe in this tool?
Completely. The formatter runs entirely in your browser using JavaScript. No SQL is ever transmitted to a server, logged, or stored. You can safely paste production queries, credentials in connection strings, or sensitive schema definitions.