ποΈ SQL Formatter
Paste any SQL query and instantly format it with consistent indentation, keyword casing, and line breaks. Supports MySQL, PostgreSQL, SQLite, T-SQL, and standard SQL dialects.
How to Use the SQL Formatter
The SQL Formatter beautifies and reformats SQL queries with consistent indentation, keyword casing, and line breaks β making complex queries easy to read and debug. Paste your raw, minified, or poorly-formatted SQL into the left panel. Select your SQL dialect from the dropdown (Standard SQL, MySQL, PostgreSQL, SQLite, T-SQL, or BigQuery) to ensure dialect-specific syntax is handled correctly. Choose whether keywords should be UPPERCASE or lowercase. Click Format SQL to see the formatted output. The formatter properly handles SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, UNION, subqueries, CTEs (WITH clauses), window functions, and nested expressions. Each clause starts on a new line with consistent two-space indentation for nested elements. Click Sample to see a complex query formatted. Click Copy to copy the formatted SQL. This tool is ideal for cleaning up auto-generated SQL from ORMs, formatting SQL from database exports, reviewing query plans, and preparing SQL for code reviews or documentation.
Frequently Asked Questions
What is a SQL Formatter?
βΊ
A SQL Formatter (also called a SQL Beautifier) reformats SQL query strings with consistent indentation, line breaks, and keyword casing to make them human-readable. Raw SQL from query builders, ORMs, or database logs is often a single long line without whitespace. A formatter breaks it into a structured, readable layout with each clause on its own line and proper alignment.
What SQL dialects are supported?
βΊ
The SQL Formatter supports Standard SQL (ANSI), MySQL, PostgreSQL, SQLite, T-SQL (Microsoft SQL Server and Azure SQL), and Google BigQuery SQL. Each dialect has slight syntax differences β for example, PostgreSQL uses $1 for parameter placeholders while MySQL uses ?, and T-SQL uses square brackets for identifiers while standard SQL uses double quotes. Selecting the correct dialect ensures dialect-specific syntax is formatted correctly.
Should SQL keywords be uppercase or lowercase?
βΊ
This is a style preference with no functional difference β SQL is case-insensitive for keywords. The traditional convention is to write SQL keywords in UPPERCASE (SELECT, FROM, WHERE, JOIN) and table/column names in lowercase. This makes keywords visually distinct from identifiers. Some modern teams prefer all lowercase for consistency with other code. Choose whichever matches your team's coding standards.
Can I use the SQL Formatter to format stored procedures?
βΊ
Yes, the formatter handles most stored procedure syntax including variable declarations, IF/ELSE blocks, WHILE loops, and BEGIN/END blocks (in T-SQL and MySQL). Very complex procedural SQL or database-specific extensions may not be formatted perfectly, but the output is still more readable than the input. For complex stored procedures, manual review of the formatted output is recommended.