SQL Formatter

Paste your SQL query to beautify it with proper indentation, line breaks, and optional keyword capitalization. Supports SELECT, INSERT, UPDATE, DELETE, and more.

Ad Space

How the SQL Formatter Works

This tool takes raw, single-line, or poorly formatted SQL queries and transforms them into clean, readable, and consistently styled output. It tokenizes your SQL input, identifies keywords and clauses, and applies proper line breaks and indentation to create a well-structured query that is easy to read, review, and debug.

Formatting Rules

The formatter applies these rules to your SQL: major clauses (SELECT, FROM, WHERE, JOIN, ORDER BY, GROUP BY, HAVING, LIMIT, INSERT, UPDATE, DELETE, SET, VALUES, UNION, EXCEPT, INTERSECT) start on new lines. Sub-clauses and column lists are indented. Keywords can be automatically uppercased for visual distinction. Commas in column lists trigger appropriate line breaks.

Why Format SQL Queries?

SQL queries in production codebases frequently become long and complex, spanning dozens of joins, subqueries, and conditions. When these queries are written as a single line or with inconsistent formatting, they become extremely difficult to read and debug. A well-formatted query reveals its logical structure at a glance.

Code reviews benefit enormously from consistent SQL formatting. Reviewers can quickly identify the tables being queried, the join conditions, the filtering logic, and the aggregation rules. Without formatting, reviewers spend more time parsing the query structure than evaluating the logic. Many development teams enforce SQL formatting standards for exactly this reason.

Keyword Capitalization

The industry-standard convention is to write SQL keywords in uppercase (SELECT, FROM, WHERE) and table/column names in their original case. This creates a clear visual distinction between SQL syntax and your data model. This tool uppercases keywords by default, but you can disable this option if your team prefers a different convention.

Indentation Options

You can choose between 2-space and 4-space indentation. Two-space indentation keeps queries more compact, which is helpful for wide queries with many columns. Four-space indentation provides stronger visual separation of nested clauses, making deeply nested subqueries easier to follow. Choose the style that matches your team standards.

Supported SQL Dialects

The formatter handles standard SQL syntax that works across all major database systems including PostgreSQL, MySQL, SQL Server, Oracle, SQLite, and others. It correctly handles common clause keywords, string literals, numeric values, and standard operators. While it may not handle every vendor-specific extension, it works well for the vast majority of real-world queries.

Common Use Cases

Use this tool when copying queries from application logs, when formatting queries for documentation, when preparing SQL for code reviews, when cleaning up queries pasted from database management tools, or when debugging complex queries by making their structure visible. It is also useful for learning SQL by seeing how well-structured queries should look.

Privacy Notice

All formatting happens entirely in your browser. Your SQL queries are never transmitted to any server, making this tool safe for queries containing sensitive table names, column names, or data values.