What the SQL Formatter does
This page turns a single-line or badly wrapped SQL statement into something readable. Clause keywords are recognised regardless of case, moved onto their own lines, and the clauses that follow the main verb are indented by two spaces, so the structure of the query becomes visible at a glance. The page never connects to a database and never parses your statement as SQL; it works on the text alone.
Compress goes the other way. Every run of spaces, tabs and newlines collapses to a single space and the ends are trimmed, giving a statement you can drop into a string literal, a URL parameter or a shell command. A practical sequence is to compress a paste out of a chat message, copy that single line back into the box, and format it to restore the structure the message lost.
How to use it
- Paste the statementDrop a SELECT, INSERT, UPDATE or CREATE TABLE into the box, one statement per run. A sample query is loaded already, so you can watch what the buttons do before touching your own SQL.
- Format or compressFormat spreads clauses over lines with two-space indents. Compress folds whitespace down to single spaces and trims the two ends. Neither button edits the text sitting in the input box, only the result area below it.
- Format a copyBoth buttons read the input box every time, so to rebuild structure after compressing, paste the single-line result back into the box and press Format again. The result area is plain text, so dragging a selection out of it works normally.
- Clear and repeatClear empties the input and the result together, and nothing is stored between runs. If a formatted statement matters to you, copy it out before closing the tab or pasting a different query into the same box.
Options and formats
Things to watch out for
Frequently asked questions
Does formatting change what the query does?
No. The tool only inserts newlines, indentation and spaces between existing tokens, so the meaning the database sees is unchanged. The single exception is whitespace inside a quoted value, which Compress collapses. Compare a formatted run against your original before committing SQL to a repository.
Which SQL dialects are supported?
The keyword list is generic ANSI-style vocabulary, which covers the clauses the formatter knows how to pull apart. Dialect-specific constructs such as Postgres :: casts, MySQL backticks or T-SQL bracket identifiers are not on that list, so those pieces stay where they are instead of being split onto their own lines.
Why did my keywords stay lowercase?
Detection ignores case, but the matched text is written back exactly as you typed it. The tool moves keywords rather than restyling them. If you want uppercase keywords throughout, do a whole-word find and replace in your editor after formatting; that combination is usually faster than typing the query again.
Can it repair a broken query?
No. Reformatting never fixes syntax. A statement with a missing comma or an unclosed parenthesis comes out looking tidy and still fails when the database reads it. Run the formatted text through your database client to confirm it executes before trusting the layout.
What happens with a very long query?
Everything runs in the page with ordinary string operations, so a query containing hundreds of keywords returns a result quickly. Extremely large scripts produce a long result area that is slow to scroll through. Splitting a dump into single statements keeps the page responsive and the output easier to read.
Is the output safe to paste into a shell?
Only after compressing it. A formatted statement holds literal newlines, and pasting that into a terminal sends each line as a separate command. Compress first, then wrap the single-line result in quotes and check that the shell will not expand characters such as asterisks or semicolons inside it.