Paste a query into the SQL formatter and get it back with each clause on its own line, column lists and AND/OR conditions indented, and subqueries nested. You can also minify SQL to one line per statement. String literals, quoted identifiers and comments are copied exactly. The formatter runs in your browser and nothing you paste is uploaded.
Loading the tool… It runs in your browser and needs JavaScript.
Table of Contents
How to use the SQL formatter
Paste one or more statements, separated by semicolons. Choose the dialect, keyword case (UPPER, lower or as typed) and indent, and the result updates as you type. The formatter puts major clauses such as SELECT, FROM, WHERE, GROUP BY, ORDER BY, INSERT INTO, VALUES, UPDATE, SET and UNION on new lines. Each JOIN gets its own line, and every item in a column list goes on its own row.
Subqueries in brackets are indented one level deeper. Function calls, IN (...) lists, CASE expressions and window clauses stay on one line, so short expressions remain compact. The AND inside BETWEEN x AND y is never split.
What the formatter never changes
It uses its own tokenizer, so text inside quotes is never mistaken for SQL. These are copied byte for byte:
- single-quoted strings, including doubled quotes (
'it''s') and, in MySQL mode, backslash escapes; - backtick and double-quoted identifiers, even when they are keywords, such as
`order`; - comments:
-- ...,/* ... */and, in MySQL mode,# ...; - PostgreSQL dollar-quoted bodies (
$$ ... $$,$fn$ ... $fn$) andE'...'strings.
The dialect setting matters for a few details. In MySQL, # starts a comment, double quotes are strings by default, and -- only starts a comment when a space follows it, so a--1 means a - -1. In PostgreSQL, backslashes in ordinary strings are literal, because standard_conforming_strings has been on by default since version 9.1.
Minify mode
Minify puts each statement on one line and removes ordinary comments. It keeps MySQL executable comments (/*! ... */) and optimiser hints (/*+ ... */), because MySQL acts on them. Keyword case still follows your choice.
Limits
This is a layout tool, not a SQL parser: it does not check whether your query is valid. It does warn about unclosed quotes, comments and brackets. Stored procedure bodies and client commands such as DELIMITER are formatted as plain statements. Input is limited to 1 MB.
For server admins: tidying slow-log queries
Queries from the slow query log or the process list usually come as one long line. Summarise the log first, then paste the worst queries here to read them:
mysqldumpslow -s t -t 10 /var/log/mysql/mysql-slow.log # top 10 by total time
mysql -e "SHOW FULL PROCESSLIST\G"On MariaDB the summary tool is also installed as mariadb-dumpslow. When you run EXPLAIN FORMAT=JSON, paste its output into the JSON formatter.
At a glance



Related: AI Slow Query Advisor for MySQL and MariaDB · SQL Cheat Sheet: MySQL, MariaDB and PostgreSQL Syntax · JSON Formatter and Validator · Diff Checker: Compare Two Texts.
Official documentation (checked 9 October 2026): MySQL 8.0 Reference Manual: Comments · PostgreSQL Documentation: Lexical Structure
Frequently asked questions
Does the formatter change what my query does?
No. Only whitespace and keyword case change; strings, quoted names and comments are kept as written. Our tests run original and formatted queries in SQLite and compare the results.
Which databases does it support?
It is tuned for MySQL and MariaDB, PostgreSQL and standard SQL. Pick the dialect so comments, quotes and escapes are read the right way.
Why are my table names not upper-cased?
Words straight after FROM, JOIN, INTO, UPDATE or TABLE, and words next to a dot, are treated as names and left alone, because table names can be case-sensitive on Linux.