AltUtils

SQL Formatter

Format and beautify SQL queries for MySQL, PostgreSQL, SQLite, SQL Server and more with configurable indentation and keyword case.

CategoryDev Core
Sheet14 / 42
ProcessingIn your browser
Formatted SQL

What is the SQL Formatter?

This SQL Formatter turns long, single-line or inconsistently indented queries into clean, readable SQL. It understands the syntax of 20 dialects — Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, DuckDB, ClickHouse, Trino/Presto, Spark, Hive, Db2, SingleStore, TiDB and Couchbase N1QL — so dialect-specific quoting, operators and keywords are handled correctly.

You control the style: uppercase, lowercase or preserved keywords, data types and function names; 2 spaces, 4 spaces or tabs; standard or tabular indentation; line breaks before or after AND/OR; the maximum width of parenthesized expressions; and blank lines between statements. Minify mode does the opposite, stripping comments and extra whitespace while keeping string literals, quoted identifiers and optimizer hints (/*+ … */) intact.

If a query cannot be parsed, the formatter shows the exact line and column with a pointer to the problem, which is often a sign that a different dialect should be selected. Formatting runs entirely in your browser using the open-source sql-formatter library, so schemas and queries are never uploaded.

Frequently asked questions

Why format SQL?
Queries generated by ORMs, copied from logs or written in a hurry are hard to read. Consistent indentation and line breaks make JOIN conditions, WHERE clauses and subqueries easy to follow, which speeds up debugging and code review.
Which SQL dialect should I choose?
Pick the database the query runs on. Dialects differ in identifier quoting ("x", `x` or [x]), string escapes, parameter placeholders and keywords. If you see a parse error with Standard SQL, switching to the specific dialect usually fixes it.
Does formatting change what the query does?
No. Only whitespace, line breaks and the letter case of keywords, types and functions change. Avoid the experimental identifier-case option if your database treats quoted or unquoted identifiers case-sensitively.
What does Minify do?
It removes comments and collapses whitespace into the shortest equivalent query, useful for embedding SQL in code or logs. Optimizer hints and MySQL /*! … */ comments are kept because they affect execution.
Should SQL keywords be uppercase?
Databases treat keywords case-insensitively, but uppercase keywords (SELECT, FROM, WHERE) are a widespread convention that separates SQL syntax from table and column names. Choose whatever your team's style guide uses.
Is my SQL sent to a server?
No. The formatter runs as JavaScript in your browser, so proprietary schemas, table names and data in your queries never leave your device.