Google PlayGoogle Play
Temp Mail Logo

Temp Mail safeguards your privacy while keeping your inbox free from spam.

🗄 Format · Minify · Uppercase · MySQL · PostgreSQL · SQLite · SQL Server

SQL Formatter

Free SQL formatter and beautifier. Paste any SQL query to instantly format with proper indentation and keyword casing, or minify to a single line. Works with MySQL, PostgreSQL, SQLite, and SQL Server.

✓ Format & minify✓ Uppercase or lowercase✓ All major dialects✓ Instant preview✓ No signup
SQL Input
Formatted SQL
What this tool does

Free SQL formatter: beautify SQL queries with proper indentation for MySQL, PostgreSQL, and SQL Server

How SQL formatting works and what the options do

This SQL formatter tokenises your query, identifying keywords, identifiers, string literals, and comments, and reformats it with each major clause on its own line and column lists indented for readability. It handles SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY, LIMIT, INSERT, UPDATE, DELETE, and CREATE TABLE statements. String literals and comments are preserved exactly as written.

The keyword casing options let you match your team's SQL style guide. Uppercase keywords (SELECT, FROM, WHERE) is the traditional convention and makes keywords visually distinct from identifiers. Lowercase (select, from, where) is preferred by some modern style guides. Neither affects query execution. SQL keywords are case-insensitive in all major databases.

Minify mode collapses your formatted query to a single line. Useful for copying into application code where a multiline string would be awkward. All formatting is done client-side: your SQL queries are never sent to any server, keeping sensitive table schemas and data structures private.

Features and capabilities
Format SQL
Adds proper indentation and line breaks, each clause on its own line.
Minify SQL
Collapses to a single line for use in application code strings.
Keyword Casing
Choose UPPERCASE or lowercase for SQL keywords.
Indent Size
2 or 4 spaces to match your team code style.
String Preservation
String literals and comments preserved exactly as written.
Multi-Statement
Multiple SQL statements separated by ; are each formatted.
Instant Preview
Formats as you type, live preview of every keystroke.
100% Client-Side
SQL never leaves your browser, safe for sensitive schemas.
Examples

SQL formatting examples: SELECT with JOINs, aggregates, and subqueries before and after formatting

Real SQL queries showing unformatted input and clean formatted output
BeforeMinified query: hard to read
SELECT u.id,u.name,COUNT(o.id) as orders,SUM(o.total) as revenue FROM users u LEFT JOIN orders o ON u.id=o.user_id WHERE u.active=1 AND u.created_at>='2024-01-01' GROUP BY u.id,u.name HAVING COUNT(o.id)>0 ORDER BY revenue DESC LIMIT 50
AfterFormatted: each clause on its own line
SELECT u.id, u.name, COUNT(o.id) as orders, SUM(o.total) as revenue FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.active = 1 AND u.created_at >= '2024-01-01' GROUP BY u.id, u.name HAVING COUNT(o.id) > 0 ORDER BY revenue DESC LIMIT 50
FAQ

Frequently asked questions about SQL formatting and query best practices

Why should I format SQL queries?
Formatted SQL is dramatically easier to read, debug, and maintain. A single-line query with 10 joins and 20 conditions is nearly impossible to understand at a glance. Formatted SQL puts each clause on its own line, indents subquery columns, and makes the logical structure immediately clear. This reduces the time to review queries in code reviews, makes it easier to spot logic errors, and helps onboard new team members who need to understand existing queries.
What SQL dialects does this formatter support?
This formatter handles standard SQL that works across MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), and Oracle. It correctly formats SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY, LIMIT, INSERT, UPDATE, DELETE, CREATE TABLE, and common functions like COUNT, SUM, AVG, COALESCE, and CAST. Dialect-specific syntax (T-SQL stored procedures, PL/pgSQL blocks, Oracle PL/SQL) may not format perfectly but core DML and DDL statements work correctly.
Should SQL keywords be uppercase or lowercase?
This is a style preference, but uppercase keywords are the traditional convention and the most widely followed SQL style guide recommendation. Uppercase SELECT, FROM, WHERE (etc.) visually separates keywords from identifiers (table names, column names), making queries easier to scan. Some modern style guides (like GitLab's) prefer lowercase. What matters most is consistency. Pick one style and stick to it across your codebase. This tool offers both uppercase and lowercase keyword options.
What is SQL injection and does formatting help?
SQL injection is a security vulnerability where user input is inserted directly into a SQL query string, allowing attackers to manipulate the query. For example, if a query is built as 'SELECT * FROM users WHERE name = ' + userInput, a malicious user can input ' OR 1=1. To return all users. Formatting does not prevent SQL injection. It's a readability tool only. Prevention requires parameterised queries (prepared statements) or ORMs that handle escaping automatically.
How do I minify SQL?
SQL minification removes all whitespace, reducing the query to a single line. This has marginal performance benefits (slightly smaller network payloads) but makes the query unreadable. Most ORMs and query builders handle minification automatically. If you need to minify manually, select the Minify tab in this tool. Note that SQL minification is rarely necessary in practice. Database query planners don't benefit from whitespace removal, and most connection pooling and caching systems ignore formatting.

Need a disposable email address?Get a free instant throwaway email. No signup, no trace.

Get Free Temp Mail →