SQL Formatter & Beautifier

Format, beautify, and minify SQL queries instantly. Pretty print with configurable indentation, keyword uppercasing, syntax highlighting, and proper subquery nesting. Supports SELECT, JOIN, subqueries, CTEs, CASE expressions, and all major SQL clauses. Free, runs entirely in your browser -- no data ever leaves your machine.

Input Paste or type SQL
Output
Formatted output will appear here...

Features

Smart Formatting

Automatically places each SQL clause on its own line with proper indentation. Handles SELECT lists, JOIN chains, WHERE conditions, subqueries, and CTEs with intelligent nesting.

🎨

Syntax Highlighting

Color-coded output distinguishes keywords, strings, numbers, functions, and comments at a glance. Line numbers make it easy to reference specific parts of your query.

Configurable Options

Choose between 2-space, 4-space, or tab indentation. Toggle keyword uppercasing on or off. Minify queries to a single line for production use.

🔒

100% Client-Side

All formatting happens in your browser. Your SQL queries are never sent to any server, making it completely safe for sensitive database queries and proprietary schemas.

About SQL Formatting

SQL (Structured Query Language) is the standard language for managing and querying relational databases. Whether you are writing queries for PostgreSQL, MySQL, SQL Server, SQLite, or Oracle, well-formatted SQL is essential for readability, maintainability, and collaboration. Raw or compressed SQL queries can be extremely difficult to read and debug, especially when they involve multiple JOINs, subqueries, or complex WHERE clauses.

Why Format SQL?

Formatting SQL queries adds proper indentation, line breaks at clause boundaries, and consistent keyword casing. This makes the logical structure of the query visible at a glance -- you can immediately see which tables are being joined, what conditions are applied, how results are grouped, and what ordering is used. Well-formatted SQL is easier to review in pull requests, debug when results are unexpected, and maintain as requirements change over time.

How This Tool Works

Paste your SQL into the input pane and click Format to beautify it with syntax highlighting and line numbers. The tool tokenizes your SQL, identifies keywords, handles string literals and comments without modification, and applies intelligent indentation rules. Click Minify to compress your query to a single line with comments stripped. Everything runs entirely in your browser -- no data is ever sent to a server.

Common Use Cases

Frequently Asked Questions

What is SQL formatting?
SQL formatting (also called SQL beautifying or pretty printing) is the process of adding proper indentation, line breaks, and consistent keyword casing to SQL queries to make them easier to read, understand, and maintain. A well-formatted query places each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, etc.) on its own line with consistent indentation for sub-clauses like ON conditions, AND/OR predicates, and CASE/WHEN branches. This visual structure mirrors the logical structure of the query, making it much easier to understand complex queries at a glance.
How do I format a SQL query?
To format a SQL query using this tool, paste your raw, minified, or unformatted SQL into the input textarea on the left side. Select your preferred indentation level (2 spaces, 4 spaces, or tabs) from the dropdown menu, optionally check the "Uppercase keywords" checkbox to convert all SQL keywords to uppercase, then click the "Format" button. The tool will parse your SQL, identify keywords and clauses, and display a beautifully formatted version in the output pane with syntax highlighting and line numbers. You can then copy the formatted output to your clipboard or download it as a .sql file.
Does this tool support subqueries and CTEs?
Yes. The formatter properly handles nested subqueries by detecting SELECT statements inside parentheses and increasing the indentation level for the subquery contents. When the subquery ends, the indentation returns to the previous level. It also supports Common Table Expressions (WITH clauses / CTEs), which are formatted with proper indentation for each CTE definition before the main query. This makes even deeply nested queries with multiple CTEs and subqueries readable and well-structured.
What SQL dialects are supported?
The formatter supports standard SQL syntax that works across all major relational database management systems. It handles keywords and syntax common to PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server, Oracle Database, and other SQL-compliant databases. This includes SELECT, FROM, WHERE, all JOIN variants (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL), GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, UNION/INTERSECT/EXCEPT, CASE/WHEN/THEN/ELSE/END, INSERT INTO, UPDATE, DELETE FROM, CREATE TABLE, ALTER TABLE, DROP TABLE, and aggregate functions like COUNT, SUM, AVG, MAX, and MIN.
What is SQL minification?
SQL minification removes all unnecessary whitespace, line breaks, and comments from a SQL query, compressing it into a single compact line. The resulting minified SQL is functionally identical to the original but takes up significantly less space. This is useful when embedding SQL in application source code where multi-line strings are inconvenient, reducing payload size when sending SQL queries over network APIs, storing queries in configuration files or environment variables, and logging queries in compact format. Our Minify button instantly compresses your SQL and shows you exactly how many characters were saved.
Is my SQL data safe?
Absolutely. This tool runs entirely in your browser using client-side JavaScript. Your SQL queries are never sent to any server, stored in any database, or logged anywhere. All formatting, minification, and syntax highlighting happens locally on your machine. This makes it completely safe to use with sensitive or proprietary SQL code, including queries that reference internal table names, column names, or contain data values. You can verify this by checking the network tab in your browser's developer tools -- no requests are made when you format or minify your SQL.
Does the formatter handle comments?
Yes. The formatter recognizes both single-line comments (prefixed with --) and multi-line block comments (enclosed in /* */). In formatted output, comments are preserved and placed on their own lines at the appropriate indentation level. In minified output, comments are stripped entirely to produce the most compact result possible. String literals that contain comment-like syntax (e.g., 'value -- not a comment') are correctly identified as strings and left unchanged.

Explore More Developer Tools

Check out our other free developer tools. Format JSON, parse AWS ARNs, decode JWTs, generate Kubernetes manifests, and more -- all from your browser with no sign-up required.

JSON Formatter → K8s YAML Generator →