SQL Formatter
The SQL Formatter beautifies SQL queries by adding proper indentation, line breaks, and keyword capitalization. Well-formatted SQL is easier to read, debug, and review. This formatter handles SELECT, INSERT, UPDATE, DELETE, CREATE, and ALTER statements, along with JOINs, subqueries, and CTEs. It follows common SQL formatting conventions, capitalizing keywords, aligning columns, and indenting nested queries. It is perfect for working with complex queries or cleaning up auto-generated SQL.
Formula
Formatting rules: - Keywords: UPPERCASE (SELECT, FROM, WHERE) - Functions: lowercase or UPPERCASE - Indentation: 2 spaces for subqueries - Newlines after each clause - Comma-aligned column lists Supports: MySQL, PostgreSQL, SQL Server, Oracle
Example
Input (minified): select id,name,email from users where active=1 order by name Output (formatted): SELECT id, name, email FROM users WHERE active = 1 ORDER BY name;
How to Use
- Paste your SQL query into the input field
- Select SQL dialect if needed
- Click format to beautify the query
- Review the formatted SQL with proper indentation
- Copy the formatted SQL for your use
Frequently Asked Questions
What SQL dialects are supported?
The formatter supports standard SQL and works with MySQL, PostgreSQL, SQL Server, Oracle, and SQLite. Some dialect-specific syntax (like PostgreSQL's dollar-quoting) may not be perfectly formatted. Always review the output for dialect-specific features.
Should keywords be uppercase or lowercase?
The formatter defaults to uppercase keywords (SELECT, FROM, WHERE), which is the most common convention. You can configure it to use lowercase if your team prefers. Consistency is more important than the choice.
Does the formatter handle complex queries?
Yes. The formatter handles JOINs, subqueries, CTEs (WITH clauses), UNION, CASE expressions, and window functions. It properly indents nested queries and aligns joined tables.
Can formatting change SQL behavior?
No. Formatting only adds whitespace and capitalization for readability. The query execution remains identical. However, be careful with string literals — the formatter should not modify content within quotes.
Should I format SQL for production?
Yes, unlike CSS/JS, formatted SQL has no performance impact. Database engines ignore whitespace. Keep SQL formatted in production for easier debugging and code review. Minification is not needed for SQL.