SQL Formatter Guide
SQL copied from logs, ORMs or a colleague's message often arrives as one long line, or with inconsistent indentation and keyword casing that makes joins and conditions hard to follow. A formatter rewrites the query with every clause on its own line, consistent indentation and uniform keyword case, without changing what the query does. This tool understands the syntax of 19 SQL dialects — from PostgreSQL, MySQL and SQL Server to BigQuery, Snowflake and ClickHouse — and can also minify a query into a single compact line.
⚙️ Key Features
- Dialect-aware formatting for 19 databases, including PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark, Trino, DuckDB and ClickHouse.
- Indent with 2 spaces, 4 spaces or tabs; keywords, functions and data types in UPPER case, lower case, or as written.
- Choose whether AND / OR start or end a line.
- Minify mode removes comments and extra whitespace while keeping string literals, quoted identifiers and optimizer hints intact.
- Clear syntax errors with line and column, plus statement, line and size counts.
- Open or drop .sql files, copy, and download the result.
📖 How to Use
- Paste a query, drop a .sql file onto the input, or click 'Sample'.
- Select the dialect your database uses, so that dialect-specific syntax such as TOP, backtick identifiers or $$-quoted strings is understood.
- Adjust the indentation, keyword case and AND / OR placement; the formatted query updates as you type.
- Switch to 'Minify' to get a single-line version for embedding in code or config, then copy or download it.
SQL is formatted and minified locally in your browser using the open-source sql-formatter library. Your queries never leave your device: nothing is uploaded, logged or saved on a server.
Frequently Asked Questions (FAQ)
Does formatting change what my query does?
No. The formatter only changes whitespace, line breaks and the letter case of keywords. Table and column names, string literals and quoted identifiers are left exactly as written, so the database executes the same query.
Why do I get a syntax error for a query that runs fine?
Usually the selected dialect doesn't match your database. For example, backtick-quoted names are MySQL syntax, square brackets and TOP are SQL Server, and $$ strings are PostgreSQL. Pick the matching dialect and try again. Placeholders such as ? or :name are supported in most dialects.
What does minifying remove?
Line and block comments, line breaks and repeated spaces, plus spaces around commas and parentheses. Optimizer hints (/*+ … */) and MySQL version comments (/*! … */) are kept because they affect execution, and nothing inside quotes is touched.
Is it safe to paste production queries?
Yes. Formatting runs entirely in your browser, so queries — and any table names, customer IDs or values inside them — are never sent to a server or stored.