How to use the SQL Formatter / Beautifier
Format your SQL query in four steps:
1
Paste your SQL
Paste any SQL — minified, auto-generated, or badly indented — into the input box. You can also upload a .sql file.
2
Choose your dialect and options
Select your SQL dialect (MySQL, PostgreSQL, SQLite, BigQuery, T-SQL, or Standard SQL), set your preferred indentation (2 spaces, 4 spaces, or tab), and toggle keyword uppercasing on or off.
3
Click Format SQL
Press the Format SQL button. The tool re-formats your query with consistent indentation, line breaks at clause boundaries, and optional syntax highlighting.
4
Copy or download
Click Copy to send the formatted SQL to your clipboard, or Download to save it as a .sql file for your project.
When to use this tool
Use the SQL formatter whenever SQL readability and consistency matter:
- →Formatting auto-generated ORM queries before including them in documentation or bug reports
- →Cleaning up minified or single-line SQL exported from BI tools and query builders
- →Standardising SQL style across a team — consistent indentation and keyword casing
- →Preparing SQL code for code review where readability is essential for accurate feedback
- →Reformatting long queries with complex JOINs and subqueries for easier debugging
- →Beautifying stored procedures and views before committing them to version control
- →Converting SQL written by different authors into a single consistent style for a codebase
Frequently asked questions
Q:Which SQL dialects does the formatter support?
The formatter supports Standard SQL, MySQL, PostgreSQL, SQLite, BigQuery, and T-SQL (SQL Server). Each dialect has slightly different reserved words and syntax conventions — selecting the correct dialect ensures the formatter handles dialect-specific keywords correctly.
Q:Does the formatter validate my SQL for errors?
The formatter parses your SQL to apply formatting and will show an error if the input cannot be parsed. However, it does not connect to a database and cannot catch logical errors, missing indexes, or permission issues — it only validates that the SQL is syntactically parseable by the formatter.
Q:Can I format SQL with CTEs (WITH clauses) and subqueries?
Yes — the formatter handles CTEs (Common Table Expressions), nested subqueries, CASE expressions, window functions, and complex multi-JOIN queries. Each clause is indented and line-broken at the appropriate level, making even deeply nested queries readable.
Q:What does the UPPERCASE keywords option do?
When enabled, all SQL reserved words (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, etc.) are converted to uppercase, which is the widely accepted SQL convention. When disabled, keywords are left in the case they appear in the input. Uppercasing keywords visually separates SQL syntax from table and column names.
Q:Does this tool send my SQL queries to a server?
No — the SQL formatter runs entirely in your browser using the sql-formatter JavaScript library. Your queries never leave your device. This makes it safe to format queries containing sensitive schema names, column names, or data values.
Q:Can I format multiple SQL statements at once?
Yes — paste a script containing multiple statements separated by semicolons. The formatter processes all statements and formats each one with consistent indentation and spacing in a single pass.
Q:What is the difference between formatting and minifying SQL?
Formatting expands SQL with indentation and line breaks to maximise human readability — use it for code review, debugging, and documentation. Minifying collapses SQL to a single line with minimal whitespace to reduce file size and transmission overhead — use it for production query strings in application code. Use our SQL Minifier tool for the reverse operation.