SQL Formatter

Your data never leaves your browser

Format and beautify SQL queries for MySQL, PostgreSQL, SQLite, T-SQL, and Standard SQL. Keyword casing control. Runs 100% in your browser.

Input - SQL
Output - Formatted SQL
Ctrl+Shift+CCopyCtrl+KClear

Share this tool

Found it useful? Help a fellow developer discover it.

https://developertoolkit.dev/tools/sql-formatter

Supported dialects

Standard SQL

ANSI SQL syntax. Works for most common SELECT, INSERT, UPDATE, DELETE, and DDL statements.

MySQL

MySQL-specific functions, backtick identifiers, and LIMIT/OFFSET syntax.

PostgreSQL

PostgreSQL dollar-quoted strings, RETURNING clauses, and :: cast syntax.

SQLite

SQLite-compatible formatting. Handles PRAGMA statements and WITHOUT ROWID tables.

T-SQL (SQL Server)

Microsoft SQL Server syntax, TOP, NOLOCK hints, square-bracket identifiers, and GO separators.

Why format SQL?

Minified or machine-generated SQL is difficult to read and audit. Well-formatted SQL puts each clause on its own line, indents subqueries and JOIN conditions, and uses consistent keyword casing making it far easier to spot logical errors, missing conditions, or implicit cross joins. Formatted SQL is also easier to diff in code review and to copy into query editors that don't have built-in formatting. This tool formats SQL instantly in your browser, which means production query strings, credentials embedded in connection strings, and sensitive schema details never leave your device.

How to format a SQL query

  1. Select the correct dialect from the dropdown. MySQL, PostgreSQL, T-SQL, SQLite, and Standard SQL each have slightly different reserved words and syntax. Matching the dialect produces the most accurate keyword recognition.
  2. Choose your preferred keyword casing. UPPERCASE is the traditional style and helps keywords stand out from identifiers. Lowercase is preferred in some codebases. Preserve keeps the original casing.
  3. Paste your raw or minified SQL into the input panel. Multi-statement queries separated by semicolons are supported.
  4. Click Format (or press Ctrl+Enter) to apply consistent indentation and clause separation.
  5. Click Copy to copy the result, or Download to save it as a .sql file.

Frequently Asked Questions

How do I format a SQL query online?

Paste your SQL into the input panel, select the correct dialect from the dropdown (MySQL, PostgreSQL, T-SQL, SQLite, or Standard SQL), choose your preferred keyword casing, then click Format or press Ctrl+Enter. The formatted query appears in the output panel ready to copy.

Can this formatter handle complex SQL with subqueries and CTEs?

Yes. The sql-formatter library handles SELECT statements with multiple JOINs, nested subqueries, common table expressions (WITH ... AS), window functions (OVER PARTITION BY), and most DML and DDL statements. Very long or highly nested procedural SQL with deeply nested BEGIN/END blocks may have occasional edge cases.

Why does formatted SQL look different from what my IDE produces?

Every formatter applies its own style rules for line breaks, indentation width, and clause placement. There is no universal SQL formatting standard. The output follows the sql-formatter library conventions. The logical meaning of the query is always identical. Only whitespace changes.

Does formatting change the behaviour of my SQL?

No. Formatting only affects whitespace and keyword casing, which SQL parsers treat as insignificant. The logical meaning of a query is identical before and after formatting.

Why should I use the correct dialect?

Each dialect has slightly different reserved words, function names, and syntax rules. Using the matching dialect produces more accurate keyword recognition and avoids false formatting errors on dialect-specific syntax like MySQL backticks or PostgreSQL :: casts.

Can I format stored procedures or triggers?

Yes, for dialects that support them. Stored procedure bodies (CREATE PROCEDURE … BEGIN … END) are formatted correctly for MySQL, PostgreSQL, and T-SQL. Very complex procedural SQL with nested BEGIN/END blocks may have edge cases.

Is my SQL query sent to a server?

No. All formatting happens client-side using the sql-formatter npm package compiled for the browser. Your query strings, table names, and any embedded data values never leave your device.

What is the difference between UPPERCASE and lowercase keyword casing?

Convention only. The SQL standard does not mandate keyword casing. Both SELECT and select are valid. UPPERCASE keywords are the traditional style and aid readability by visually distinguishing keywords from identifiers. Lowercase is preferred in some codebases. Preserve keeps whatever casing the original input used.

Related Tools