How to Format a SQL Query
Queries have a way of arriving as a single enormous line — pulled out of a log, copied from application code, or written in a hurry at three in the afternoon. Formatting breaks them onto sensible lines so the structure becomes visible: which tables are joined, what the conditions actually are, and where the query is doing more work than it needs to.
Paste your query
One line or many, a single statement or a whole script. Drop a .sql file if you prefer.
Choose your conventions
Indent size and whether keywords should be uppercase - the two things teams disagree about.
Copy it back
Or switch to minify when you need the query compressed into a single line for embedding.
Why Tokenising Matters
A naive formatter works by find and replace: look for the word from, put a newline before it, capitalise it. This breaks immediately on real queries. A column called order_from gets mangled. A string literal containing the word select gets rewritten. A comment mentioning where acquires a line break in the middle of it.
This formatter tokenises first— walking the query character by character and classifying each piece as a keyword, a string, a comment, a number, an identifier or punctuation. Once that is done, quoted content and comments simply are not keywords, and cannot be treated as such. Formatting then operates on the token stream rather than on raw text, which is why it does not corrupt anything.
A useful consequence: because the tokens are already classified, the tool can also tell you which tables the query touches and what kind of operation it is. That is genuinely handy when reviewing a query someone else wrote, or when checking that a script does not quietly contain a DELETE you did not expect.
Formatting Conventions Worth Knowing
Uppercase keywords are the convention
Not because SQL requires it - it is case-insensitive - but because it separates language from data at a glance, which matters in a long query.
One clause per line
SELECT, FROM, WHERE and each JOIN starting a new line is what makes structure visible. It is the single most useful thing formatting does.
Leading AND and OR
Putting boolean operators at the start of a line rather than the end makes conditions easy to scan and easy to comment out individually.
Minify for embedding, not for storage
A single-line query is convenient in a config value or a log line, but keep the formatted version in your codebase where people have to read it.
Frequently Asked Questions
How do I format SQL online for free?
Paste your query and the formatted version appears immediately. Free, no signup, and nothing is uploaded.
Is my query sent to a server?
No. Formatting happens entirely in your browser, which matters because queries often contain table names, schemas and sometimes real data.
Will formatting change what my query does?
No. Only whitespace and keyword casing change. SQL is case-insensitive for keywords, so the query is functionally identical.
Does it handle strings and comments correctly?
Yes. The query is tokenised first, so a keyword inside a string literal or a comment is never treated as a keyword.
Which SQL dialects are supported?
The formatting is dialect-neutral and works with MySQL, PostgreSQL, SQL Server, SQLite and standard SQL, since it operates on structure rather than semantics.
Why uppercase keywords?
Convention rather than requirement. It separates the language from your table and column names, which makes long queries far easier to scan.
What does minify do?
It strips comments and collapses the query onto one line, which is useful when embedding SQL in a config file or a single log entry.
Can it format multiple statements?
Yes. Statements separated by semicolons are formatted individually with a blank line between them.
What does the tables list show?
Every table referenced after FROM, JOIN, UPDATE or INSERT INTO - a quick way to see what a query touches before running it.
Does it validate my SQL?
No. It formats whatever you give it. A query with a syntax error will still be formatted, just not made correct.
Is there a size limit?
Files above 5 MB are rejected because browser processing becomes slow.
Is this SQL formatter really free?
Completely free, with no limits, no signup and no premium wall.
Last updated: July 21, 2026 · FlipMyFormat SQL Formatter
Written and maintained by the FlipMyFormat team
