What is SQL Formatting?
SQL formatting (also called SQL beautification) adds consistent indentation, line breaks, and keyword casing to SQL queries, making them far easier to read and debug. Production databases often store or log SQL as a dense single line — a formatter restores the structure so you can see what the query actually does.
The SQL Formatter does this instantly in your browser. No installation, no login, and your SQL never leaves your device.
When Do You Need to Format SQL?
- Reading auto-generated ORM queries that arrive as one long string
- Reviewing a colleague's pull request that changes a complex query
- Debugging slow queries in a log file where whitespace is stripped
- Preparing SQL for documentation or a code review tool that needs readable output
- Minifying a query before embedding it in an environment variable or config file
Step-by-Step: How to Use the SQL Formatter
- Open the SQL Formatter.
- Paste your SQL into the left panel.
- Select your SQL dialect from the dropdown (MySQL, PostgreSQL, SQLite, T-SQL, BigQuery).
- Choose your preferred keyword casing: UPPER, lower, or preserve.
- The formatted output appears on the right in real time.
- Click Copy to copy the result to your clipboard.
Click Load Sample to see an example query formatted before you paste your own.
Choosing the Right Dialect
Different databases have slightly different SQL syntax. Selecting the correct dialect ensures the formatter handles dialect-specific keywords and functions correctly.
| Dialect | Use when | |---|---| | MySQL | MySQL 5.x / 8.x, MariaDB | | PostgreSQL | PostgreSQL, Amazon RDS, Supabase, Neon | | SQLite | SQLite, mobile databases | | T-SQL | Microsoft SQL Server, Azure SQL | | BigQuery | Google BigQuery | | Standard SQL | Generic / dialect-agnostic queries |
When in doubt, Standard SQL works well for simple SELECT, INSERT, UPDATE, and
DELETE statements that do not use vendor-specific functions.
Keyword Casing Options
SQL keywords like SELECT, FROM, WHERE, and JOIN can be written in any case —
SQL is case-insensitive. The formatter gives you three options:
- UPPER (recommended) —
SELECT * FROM users WHERE active = true - lower —
select * from users where active = true - Preserve — keeps whatever casing was in the original input
Most style guides recommend UPPER for keywords because it visually separates keywords from identifiers (table names, column names) at a glance.
Minifying SQL
Sometimes you need the opposite of beautification — a compact single-line query for embedding in code, storing in a config file, or fitting into a logging system that truncates long lines.
Click the Minify button in the toolbar to compress your formatted SQL back into a single line with all unnecessary whitespace removed.
-- Formatted
SELECT
u.id,
u.name,
o.total
FROM
users u
JOIN orders o ON u.id = o.user_id
WHERE
u.active = true
-- Minified
SELECT u.id, u.name, o.total FROM users u JOIN orders o ON u.id = o.user_id WHERE u.active = true
Formatting Best Practices
One clause per line. Put SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY,
and HAVING each on their own line. This makes it easy to add, remove, or reorder clauses.
Indent subqueries. A subquery in a FROM or WHERE clause should be indented one
level deeper than the outer query so the structure is clear.
Align ON conditions. In a query with multiple JOIN clauses, aligning the ON
keyword consistently makes the join conditions easy to scan.
Use aliases consistently. Short aliases (u for users, o for orders) reduce
noise, but define them at first use in the FROM/JOIN clauses so they are easy to trace.
Tips and Tricks
- Ctrl/Cmd+F in the output panel opens a search box — useful for finding a specific column or table in a long query.
- The formatter works on DDL statements (
CREATE TABLE,ALTER TABLE) as well as DML. - If you paste a stored procedure or function body, the formatter handles
BEGIN…ENDblocks and indents the body correctly. - Use the Maximize icon to expand the output to full screen when working with very wide queries.
Related Tools
- SQL Formatter — Format and minify SQL queries with dialect support.
- MyBatis Log Formatter — Convert MyBatis debug logs into formatted, executable SQL.
- JSON Formatter — Format JSON data returned from SQL queries stored as JSON columns.