SQL Formatter
Paste raw SQL and get clean, syntax-highlighted output instantly. Configure keyword casing, indentation, and comma placement. Runs entirely in your browser.
The Complete Guide to SQL Formatting
Whether you are a backend developer pasting a one-liner from a ORM debug log, a data analyst untangling a legacy stored procedure, or a database administrator reviewing a colleague's migration script, a SQL formatter saves real time. This guide explains how the formatter works, what each option does, and answers the questions developers search for most often.
How to Use This Tool
Paste or type your SQL into the left panel. The formatter processes your input in real time using an event listener on every keystroke - there is no button to press. The right panel immediately shows the formatted, syntax-highlighted result. Use the options bar to adjust keyword casing, indentation width, and whether commas appear before or after each column in a list. The Copy Formatted SQL button copies the plain-text (unhighlighted) version to your clipboard so you can paste it directly into a query editor or source file. The Clear button wipes the input and resets the output.
What the Formatting Engine Does
The formatter uses a two-pass approach. First, it tokenizes the input by scanning character by character and classifying each chunk as a keyword, identifier, string literal, number, operator, comment, or punctuation. String literals (everything inside single quotes or double quotes) are captured as a single token and never modified - your data values are completely preserved. Second, it applies formatting rules: major clause keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, LIMIT, UNION) each start on a new line with no indentation. Column lists, JOIN conditions, and WHERE predicates are indented by one level. Subqueries wrapped in parentheses get an additional indent level. CASE/WHEN/THEN/ELSE/END blocks are indented inside the CASE block.
Keyword Casing Options
UPPERCASE is the traditional and most widely recognized convention. It creates a strong visual contrast between structural SQL keywords and your own data identifiers, making the query easier to scan at a glance. lowercase keywords are increasingly used in modern analytics workflows and are the default output of many query auto-formatters. Capitalized (first-letter uppercase only) is a compromise that some teams prefer for readability without the visual weight of all-caps. Whichever you pick, the formatter applies it consistently to every reserved SQL word in the query.
Comma Placement: Before vs. After
The "after column" style (col1, col2, col3) is the standard that most SQL developers learn first and is preferred in most style guides. The "before column" style (, col1, col2, col3) places the comma at the start of each new line, making it slightly easier to comment out a single column without breaking the syntax of the line above it. Both are syntactically identical to the database engine. Choose based on your team's or organization's preference.
Syntax Highlighting Reference
The output panel uses four color categories to help you visually parse query structure at a glance. Keywords (SELECT, JOIN, WHERE) appear in pink so structural words stand out immediately. String literals ('active', 'John') appear in yellow to remind you that their content is passed to the database exactly as written, with no casing changes. Operators (=, !=, AND, OR, IN, LIKE) appear in cyan. Built-in functions (COUNT, SUM, COALESCE, NOW) appear in violet. Numbers appear in orange.