SQL Formatter
Turn a messy one-line query into readable, consistently indented SQL. Pick your database dialect, keyword case and indentation, or minify a query to a single line. Your SQL never leaves your browser.
Runs in your browser. Your files are never uploaded.
Loading SQL Formatter…
How to use SQL Formatter
- Paste your SQL into the left box.
- Select the dialect that matches your database, such as MySQL, PostgreSQL, SQLite or BigQuery.
- Choose keyword case (upper, lower or as typed) and the indent size, or tick Minify to one line.
- Copy the formatted query.
Why format SQL
SQL written quickly, generated by an ORM or copied from a log is often a single long line. Formatting puts each clause on its own line, indents subqueries and aligns columns so the logic is visible: what is selected, where it comes from, how tables are joined and how rows are filtered. Readable SQL is easier to review, debug and optimise, and consistent formatting makes version-control diffs much cleaner.
Most teams agree on a style, commonly uppercase keywords such as SELECT, FROM and WHERE with lowercase table and column names. The keyword case option lets you match whichever convention your project uses.
Choosing a dialect
SQL is a standard in name, but every database has its own functions, quoting rules and extensions. Quoting is a typical example: MySQL uses backticks for identifiers, PostgreSQL and standard SQL use double quotes, and SQL Server also uses square brackets. Selecting the right dialect lets the formatter tokenise these correctly.
- Use PostgreSQL for Postgres and most Postgres-compatible databases.
- Use MySQL or MariaDB for those engines and their backtick quoting.
- Use SQLite for mobile and embedded databases.
- Use T-SQL for Microsoft SQL Server and Azure SQL.
- Use Standard SQL if you are unsure.
Tips and limits
Formatting is a readability aid, not a validator. A query that formats cleanly can still reference a table that does not exist or use a function the database lacks. For very large scripts with many statements, format them in sections to keep the browser responsive. If a stored procedure or vendor-specific statement fails to parse, try another dialect, or format only the plain SELECT, INSERT and UPDATE parts.
Parameter placeholders such as ?, $1 and :name are recognised in most dialects. Never paste real credentials or secrets into any tool as good practice, even though this one runs entirely in your browser and sends nothing over the network.
Why use this sql formatter tool
- Many dialects. Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, T-SQL, PL/SQL, BigQuery, Snowflake, Redshift, Spark, Hive, Trino and Db2.
- Keyword case control. Uppercase keywords for readability, lowercase to match your team style, or keep them as typed.
- Minify mode. Collapses whitespace and removes comments without touching string literals.
- Local only. Built on an open-source formatting library that runs in your browser; queries are never uploaded.
Frequently asked questions
Does formatting change what my query does?
No. The formatter only changes whitespace, line breaks and, if you choose, the letter case of keywords. Identifiers and string values keep their original spelling. It does not run or validate the query against a database.
Why did I get a parse error?
The formatter understands a specific dialect. Syntax from a different database, an unclosed quote or an unsupported statement can fail. Try selecting the matching dialect, or check for unbalanced brackets and quotes.
Is minified SQL safe to run?
Minifying removes comments and extra whitespace outside of quoted strings, so the query meaning stays the same. Be careful with special comments such as MySQL optimiser hints, which are comments to the formatter but meaningful to the database.
More free tools
JSON Formatter
Format, validate, beautify and minify JSON instantly. Shows the exact line and column of any error. Free and runs in your browser.
Open toolJSON to CSV
Convert a JSON array to CSV in your browser. Flattens nested objects, picks delimiters and downloads a ready .csv for Excel or Sheets.
Open toolCSV to JSON
Convert CSV to JSON in your browser. Auto-detects delimiter, uses the header row as keys, and can convert numbers and booleans.
Open tool