SQL Formatter

Format messy SQL into clean, readable queries. Configurable indentation, keyword casing, and comma style.

Input SQL
Formatted SQL
SQL Formatting Rules

• Each major clause (SELECT, FROM, WHERE, etc.) starts on a new line

• Column lists are split one-per-line with indentation

• JOIN conditions appear on their own line

• AND/OR conditions are indented under WHERE

• Subqueries are indented one level deeper

• Keywords are uppercased for readability (configurable)

Frequently Asked Questions

How do I format SQL queries online?

Paste your SQL query into the input area and click 'Format SQL'. The tool will instantly format it with proper indentation, line breaks, and uppercase keywords. You can customize the indentation size (2 or 4 spaces), toggle keyword casing, and choose trailing or leading comma style.

What SQL dialects are supported?

This formatter works with standard SQL syntax used by PostgreSQL, MySQL, SQLite, SQL Server, Oracle, and most other databases. It handles SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, JOIN types, subqueries, CTEs (WITH), CASE expressions, and window functions.

Is my SQL query sent to a server?

No. The formatter runs entirely in your browser using JavaScript. Your SQL queries — which may contain table names, column names, or business logic — never leave your device. There's no server processing, no logging, and no data storage.

Can I also minify SQL?

Yes. Click the 'Minify' button to compress your SQL query into a single line by removing all unnecessary whitespace. This is useful for embedding SQL in code strings, logs, or debugging tools where compact format is preferred.

What is 'leading comma' vs 'trailing comma' style?

Trailing comma style places commas at the end of each line (SELECT col1, col2). Leading comma style places commas at the beginning of each line (SELECT col1 ,col2). Leading commas make it easier to comment out columns and see diffs in version control. Choose your preferred style in Options.

Why should I format my SQL queries?

Formatted SQL is much easier to read, debug, review, and maintain — especially for complex queries with multiple JOINs, subqueries, or conditions. Well-formatted SQL also makes code reviews faster and reduces bugs. Most style guides recommend formatting SQL with clear indentation and one clause per line.