SQL Formatter
Beautify and format SQL queries with proper indentation and keyword casing. 100% client-side.
How to Use the SQL Formatter
- Paste your SQL query into the input area on the left (or top on mobile).
- Choose a format mode — Standard (default) for full formatting, Compact for minimal whitespace, Uppercase Keywords, or Lowercase Keywords.
- View the result — the formatted SQL appears on the right with proper indentation and line breaks.
- Copy or download — use the buttons above the output to copy to clipboard or download as a .sql file.
What This Tool Does
This SQL formatter takes raw, unformatted SQL queries and restructures them for readability. It adds line breaks before major clauses (SELECT, FROM, WHERE, JOIN, etc.), indents column lists and conditions, and applies consistent keyword casing. The formatter preserves string literals and does not modify the content inside quoted values. Everything runs in your browser with no server communication.
Features
- Standard formatting — newlines before major clauses with indented continuation lines
- Compact mode — minimal whitespace for embedding SQL in code or logs
- Keyword casing — uppercase or lowercase all SQL keywords while preserving identifier case
- String literal preservation — content inside single and double quotes is never modified
- Subquery handling — parenthesized subqueries are indented for clarity
- Privacy — your SQL never leaves your browser
Supported SQL Keywords
The formatter recognizes the full set of standard SQL keywords including: SELECT, FROM, WHERE, JOIN (LEFT, RIGHT, INNER, OUTER, CROSS, FULL), ON, AND, OR, ORDER BY, GROUP BY, HAVING, LIMIT, OFFSET, UNION, INSERT INTO, VALUES, UPDATE, SET, DELETE, CREATE TABLE, ALTER TABLE, DROP, INDEX, WITH, CASE/WHEN/THEN/ELSE/END, and aggregate functions (COUNT, SUM, AVG, MIN, MAX).
Why Format SQL?
Well-formatted SQL is dramatically easier to read, debug, and maintain. When a complex query is written on a single line, finding a specific condition or join clause requires careful scanning. Formatted SQL makes the query's logical structure immediately visible: you can see which tables are joined, what conditions are applied, and how results are grouped and ordered — all at a glance.
SQL Style Conventions
There is no universal standard for SQL formatting, but common conventions include: uppercase keywords (SELECT, FROM, WHERE) to distinguish them from table and column names, one clause per line for major keywords, indented column lists under SELECT, and aligned conditions under WHERE. This tool follows these widely adopted conventions by default.
Compact vs. Standard Mode
Standard mode prioritizes readability with generous line breaks and indentation. Compact mode reduces whitespace to a minimum, keeping the query on fewer lines while still maintaining basic keyword separation. Use compact mode when SQL is embedded in application code, logged in monitoring systems, or when screen real estate is limited.
SQL Formatting Conventions
While there is no universal SQL style guide, most teams follow common conventions: uppercase keywords (SELECT, FROM, WHERE), lowercase table and column names, each major clause on its own line, and consistent indentation for column lists and conditions. This formatter applies these conventions automatically, saving time during code reviews and improving readability across your team. For other formatting tools, check out our JSON Formatter, CSV/JSON Converter, and Diff Checker for comparing SQL before and after changes.