SQL Formatter & Beautifier

Format SQL queries with proper indentation — MySQL, PostgreSQL, SQLite, SQL Server and more

Input SQL
Formatted SQL

Supported SQL Dialects

Select the dialect matching your database for accurate formatting of dialect-specific syntax:

SQL Standard MySQL PostgreSQL SQLite SQL Server Oracle PL/SQL BigQuery Snowflake Redshift Spark SQL Hive MariaDB Trino

Why Format SQL?

Readability

Complex JOIN queries, subqueries, and CTEs become understandable when properly indented. Each clause on its own line with consistent casing makes SQL logic immediately clear.

Code review

Formatted SQL is much easier to review in pull requests. Consistent formatting removes style debates and lets reviewers focus on the logic rather than indentation.

Debugging

Auto-generated or ORM-produced SQL is often minified or poorly formatted. Beautify it to understand what query is actually being executed and where performance issues might be.

Documentation

SQL in comments, README files, and wikis is far more readable when properly formatted. Well-formatted SQL queries self-document their intent.

Frequently Asked Questions

This formatter supports 13 SQL dialects: SQL (ANSI standard), MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Amazon Redshift, Spark SQL, Hive, MariaDB, and Trino. Select the dialect that matches your database for the most accurate formatting. Dialect selection affects keyword recognition, quote style, and dialect-specific function formatting.

Both styles are valid — SQL is case-insensitive for keywords. Uppercase (SELECT, FROM, WHERE) is the traditional convention from older SQL style guides and makes it visually easy to distinguish keywords from identifiers. Lowercase is increasingly common in modern codebases. The most important thing is consistency within your codebase. Use the keyword casing selector above to choose your preferred style.

Yes — select "Oracle PL/SQL" or "SQL Server (T-SQL)" from the dialect dropdown for stored procedures, functions, triggers, and blocks. These dialects include support for procedural SQL constructs like BEGIN...END, DECLARE, IF...THEN...ELSE, loops, and exception handling.

Yes. All formatting runs in your browser using the sql-formatter JavaScript library loaded from jsDelivr CDN. No SQL queries, table names, column names, or data are sent to any server. Safe for proprietary database schemas and internal queries.

Install the SQL Formatter extension by adpyke (search "sql formatter" in Extensions). Once installed, open any .sql file and press Shift+Alt+F (Windows/Linux) or Shift+Option+F (Mac) to format. You can configure the dialect and indentation in VS Code settings under sql-formatter.dialect.

Yes — use the same library this tool uses: npm install sql-formatter, then: import { format } from 'sql-formatter'; const formatted = format(sql, { language: 'mysql', tabWidth: 2, keywordCase: 'upper' });

Related Tools