❯ SQL Formatter Live
Keyword Casing
Indentation
Commas
Raw SQL Query
Formatted SQL
Formatted output will appear here as you type.
Key Terms Explained
SQL
Structured Query Language. The standard language for managing and querying relational databases. SQL is used to insert, retrieve, update, and delete data, as well as define table structures and control access permissions.
Subquery
A SELECT statement nested inside another SQL statement. Subqueries can appear in WHERE, FROM, or SELECT clauses and are evaluated before the outer query. Also called an inner query or nested query. This formatter indents them to make their nesting level visually clear.
Clause
A distinct section of a SQL statement introduced by a keyword such as SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, or LIMIT. Each clause performs a specific role in filtering, sorting, or shaping the result set. Formatting places each clause on its own line.
Keyword Casing
The typographic convention applied to reserved SQL words like SELECT, JOIN, and WHERE. Common choices are UPPERCASE (most traditional and widely adopted), lowercase, and Capitalized (first letter only). This formatter applies your chosen casing to all reserved words without touching string literals or identifiers.
Syntax Highlighting
Color-coding of code elements by category so they can be identified at a glance. In this formatter, keywords appear in pink, string literals in yellow, operators in cyan, numbers in orange, and functions in violet, mirroring the palette of professional database IDEs.
DML
Data Manipulation Language. The subset of SQL used to read and modify data: SELECT, INSERT, UPDATE, DELETE, and MERGE. DML statements are what developers write most often and what this formatter is optimized for. The counterpart DDL (Data Definition Language) covers CREATE, ALTER, and DROP.
Tokenization
The process of breaking a raw text string into a sequence of meaningful units called tokens. For SQL, tokens include keywords (SELECT), identifiers (table names), string literals ('hello'), numbers, operators (+, =), and punctuation. Tokenization is the first step in any SQL parser or formatter.
Identifier
A name given to a database object such as a table, column, view, or alias. Identifiers can be plain (employees, order_date) or quoted with backticks or double quotes to allow reserved words or spaces. The formatter applies casing rules only to reserved keywords, never to identifiers.

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.

Frequently Asked Questions

Formatted SQL is dramatically easier to read, review, and debug. Unformatted SQL written as a single line obscures the logical structure - it is hard to see which columns are selected, which tables are joined, and what conditions apply. Well-formatted SQL makes each clause visually distinct, so teammates can review it quickly in pull requests, database administrators can spot missing indexes or inefficient joins at a glance, and you can return to your own code months later and immediately understand what it does. Consistent formatting also reduces merge conflicts in version-controlled SQL files because diffs reflect actual logic changes rather than whitespace differences.
No. SQL databases parse queries by tokenizing the input - splitting the text into keywords, identifiers, operators, and literals - then building an execution plan from those tokens. Whitespace between tokens is ignored during parsing. A query written on one line and the same query spread across twenty lines with indentation produce identical parse trees and identical execution plans. The database engine never sees your formatting; it only sees the logical structure. The only exception is whitespace inside string literals enclosed in quotes, which the formatter preserves exactly as written.
UPPERCASE keywords are the most widely adopted convention in professional and enterprise SQL. Writing SELECT, FROM, WHERE, and JOIN in uppercase while keeping table names, column names, and aliases in lowercase or snake_case makes the structural keywords visually pop out from data identifiers, which aids readability at a glance. Most official SQL documentation, database textbooks, and style guides (including those from Oracle, Microsoft, and PostgreSQL) use uppercase keywords. That said, lowercase keywords have gained traction in modern analytics and data engineering workflows, partly because many query tools auto-complete in lowercase. The important thing is consistency within a project.
No. This SQL formatter is entirely client-side. Your SQL is parsed and formatted using JavaScript running in your browser. Nothing you type is ever transmitted to AxiomApe servers or any third party. You can verify this by disconnecting from the internet after the page loads - the tool continues to work perfectly. This makes it safe to use with sensitive or proprietary queries that you would not want to send to an external service.
A subquery (also called an inner query or nested query) is a SELECT statement written inside another SQL statement. It can appear in the WHERE clause (to filter rows based on a computed set), in the FROM clause (treated as a derived table), or in the SELECT list (as a scalar subquery returning a single value). For example: SELECT name FROM employees WHERE department_id IN (SELECT id FROM departments WHERE budget > 100000). The formatter indents subqueries to make their nesting level visually clear.
This tool operates entirely in your browser. No SQL queries or any other data are ever sent to any server. All formatting and syntax highlighting is performed locally by JavaScript. This tool is not affiliated with any specific database vendor.