PureDevTools

SQL Beautifier

Format and indent SQL queries with keyword casing and syntax highlighting — runs in your browser

All processing happens in your browser. No data is sent to any server.
Indent:
Keywords:
Between queries:
Formatted Output

Formatted SQL will appear here.

SQL queries written quickly in a database client often end up as a single long line, or with inconsistent capitalization, random indentation, and subqueries that are impossible to follow. This tool formats any SQL query into clean, readable code in seconds.

What SQL Beautification Does

Formatting SQL is more than adding line breaks. A well-formatted query communicates its structure at a glance:

Keyword Casing Options

UPPERCASE is the traditional SQL convention. Keywords like SELECT, FROM, WHERE, JOIN in uppercase make them visually distinct from identifiers (table names, column names). This is the default used by most SQL style guides.

lowercase matches the style preferred by some modern teams and frameworks that use SQL in code strings. PostgreSQL documentation examples often use lowercase keywords. Choose based on your team’s existing convention.

Indent Size

Indentation depth within subqueries, CASE expressions, and WITH clauses follows your choice of 2 or 4 spaces. 2 spaces is common in tools like sql-formatter. 4 spaces matches editors that default to 4-space indent for SQL files.

Multi-Dialect Awareness

While SQL has an ANSI standard, each database system has its own dialect extensions:

Standard SQL covers ANSI syntax: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, window functions, CTEs with WITH.

MySQL / MariaDB syntax includes backtick-quoted identifiers (`table_name`), AUTO_INCREMENT, SHOW TABLES, LIMIT x,y syntax, and MySQL-specific functions like IFNULL() and GROUP_CONCAT().

PostgreSQL adds RETURNING, ON CONFLICT DO UPDATE (upsert), ARRAY[], JSONB operators, :: cast syntax, ILIKE, and dollar-quoted strings.

SQLite uses AUTOINCREMENT, INTEGER PRIMARY KEY as rowid alias, WITHOUT ROWID tables, and has minimal type system.

The formatter understands keyword sets for all four dialects and highlights them correctly in the output panel.

Minify Toggle

Minifying SQL produces a compact, single-line query suitable for embedding in application code or API calls where whitespace is irrelevant. The minifier preserves string literals and removes all formatting whitespace.

This is useful when:

Syntax Highlighting

The output panel includes SQL syntax highlighting that color-codes:

This makes it much easier to visually parse complex queries with many joins and conditions.

Privacy

All SQL formatting runs in your browser. No queries are sent to any server. This is important because SQL queries often contain:

Nothing leaves your browser.

Common Use Cases

Debugging stored procedures: Long stored procedures written over time tend to accumulate inconsistent formatting. Beautifying them before debugging makes the control flow visible.

Reading ORM-generated queries: ORMs like Hibernate, SQLAlchemy, and Sequelize generate valid but unformatted SQL when logging queries. Beautifying the logged output helps you understand what the ORM is actually doing.

Code review: SQL queries in PRs are much easier to review when properly formatted. A query that’s a single line is nearly impossible to review meaningfully.

Documentation: When writing SQL in Confluence, Notion, or README files, beautifying it first makes the documentation significantly more useful.

Learning complex queries: Formatted SQL with proper indentation makes it easier to understand multi-level subqueries, CTEs, and window functions.

SQL Formatting vs Validation

This tool formats but does not execute or validate SQL. It will not catch:

For validation, run the query against your actual database or use a SQL linter like sqlfluff.

Frequently Asked Questions

Does formatting change what the query does? No. SQL whitespace and keyword casing have no effect on how the database executes the query. select * from users and SELECT * FROM users are semantically identical.

Can I format multiple queries at once? Yes. Paste multiple semicolon-separated queries. The formatter handles each statement separately and adds a blank line between them.

What about queries with CTEs (WITH clauses)? CTEs are fully supported. Each CTE definition is formatted with its own indented block, and the main query follows with consistent indentation.

Why doesn’t my query format correctly? Very complex or unusual SQL (database-specific syntax not in the keyword list, unusual operator combinations) may not format perfectly. The formatter is token-based and handles the vast majority of real-world SQL correctly.

Can I use this for NoSQL queries? No, this tool is for SQL (relational database query language). For MongoDB queries, use a JSON formatter.

Related Tools

More Code Formatters