SQL Formatter
Format and beautify SQL queries for MySQL, PostgreSQL, SQLite, SQL Server and more with configurable indentation and keyword case.
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.
Related tools
- JSON FormatterFormat, validate, minify and explore JSON with precise error locations. Your data never leaves the browser.
- JSON to TypeScriptPaste JSON and instantly generate TypeScript interfaces or type aliases with nested types, optional fields and arrays. Free and offline.
- Regex TesterTest and debug JavaScript regular expressions with live match highlighting, capture groups, flags and replace preview.
- UUID / ULID GeneratorGenerate cryptographically random UUID v4, time-ordered UUID v7, ULID and Nano ID identifiers in bulk, and inspect or convert existing IDs — locally in your browser.
- Hash GeneratorGenerate MD5, SHA-1, SHA-256, SHA-384 and SHA-512 hashes or HMACs from text and files and verify checksums — computed locally with Web Crypto.
- JWT DecoderDecode JWT header and payload, check expiry, and verify HS, RS, PS, ES and EdDSA signatures locally with Web Crypto — your token never leaves the browser.