Layout changes, not semantics
One statement can occupy a line or fifty; the database behaves identically. Formatting breaks clauses onto lines, aligns keywords and puts each selected column on its own line so diffs reveal real changes. Indentation is two spaces, four or a tab, and uppercasing converts reserved words while leaving identifiers alone. Contents of string literals are untouched, which depends on lexing rather than pattern replacement.
Steps
- Paste SQL, multi-statement scripts and comments included.
- Choose an indent width.
- Toggle keyword uppercasing to match house style.
- Format, then copy, download a .sql file, load the sample, or clear.
- Compare before and after for unintended edits.
Why uppercasing helps
Capitalised keywords separate syntax from business names at a glance, which matters most in long queries where a fifty-column select list blurs clause boundaries. Style itself has no correct answer; consistency beats preference. If the project already agrees on all-lowercase or reversed conventions, follow it rather than letting a tool impose another, or diffs become pure noise.
Comments and dialect quirks
A formatter must respect comment boundaries: line comments run to end of line, block comments sit between slash-star pairs, and identical characters inside strings are not comments. Some dialects add rules — double quotes for identifiers, backticks permitting special characters — and ignoring them uppercases identifiers as if they were keywords. Stored procedures, triggers and dynamic SQL often defeat whole-script parsing, so format the single statement instead.
Common problems
Mistaking formatting for optimisation, when plans depend on indexes and data volume. Breaking strings that contain quotes and look like syntax. Uppercasing words inside comments and altering documentation. Merging several statements formatted without semicolons. Exploding long value lists into hundreds of lines where compactness reads better. And skipping a test run, since tool bugs exist and critical scripts deserve verification.
How teams actually use it:Write the rules into project convention and format on save, which beats retrofitting with a web page. Reviews should discuss logic, not layout noise. Migration and production scripts stay versioned so the original is always recoverable. Short queries paste well on one line while complex ones read better formatted, but both need table names and key predicates rather than half a statement.