{ }jsonkit
Format
Validate
Convert
Query
Generate
SQL

SQL Formatter & Beautifier

Reformat common SQL while preserving strings, comments, and identifiers.
Dialect
Keywords
Indent
194 B · paste or drop a file
1
✓ complete194 B → 211 B0.0 ms

About SQL Formatter

The SQL formatter turns compact or inconsistently spaced SQL into a readable layout with clear clauses, joins, conditions, and lists. Paste a query copied from application logs, an ORM trace, a migration, or a database console, then choose two- or four-space indentation and upper, lower, or preserved keyword case.

Formatting is performed locally by a conservative tokenizer. String literals, quoted identifiers, numeric values, line comments, and block comments are kept intact while common SQL keywords are cased and major clauses are separated. Your queries and embedded values never leave the browser, and the tool does not connect to a database or execute SQL.

The formatter covers practical SELECT, INSERT, UPDATE, DELETE, common joins, set operations, and everyday DDL across standard SQL, PostgreSQL, MySQL, and SQLite syntax. It is intentionally not a validating SQL parser: proprietary procedural blocks, unusual operators, or deeply dialect-specific grammar may need a dedicated database-aware formatter and should be reviewed after formatting.

How it works

Tokenize without changing literals

The formatter first recognizes quoted strings, double-quoted and backtick identifiers, comments, words, numbers, operators, and punctuation. This prevents spaces or keyword casing from being changed inside data values such as 'order by', where those characters are content rather than SQL syntax.

Break major clauses onto readable lines

SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, joins, set operations, and common write clauses receive predictable line breaks. Comma-separated select fields and assignments are indented so long queries become easier to scan and review in a pull request.

Choose keyword case and indentation

Uppercase keywords create a strong visual distinction between syntax and identifiers; lowercase suits teams whose style guide uses lowercase SQL; Keep preserves the keyword spelling in the input. Indentation changes layout whitespace only and does not rename columns or tables.

Use dialect selection as a formatting hint

The dialect option recognizes common PostgreSQL, MySQL, and SQLite keywords and quoting styles while retaining dialect-specific operators and identifiers. It does not translate SQL between databases, prove that a statement is valid, or resolve schema-dependent names.

Frequently asked questions

Does the formatter execute or validate my SQL?

No. It only reformats text and never connects to a database. A readable result is not proof that the query is syntactically valid, safe, or supported by your database version; use the database's parser or EXPLAIN tooling for that.

Which SQL dialects are supported?

The practical formatting rules cover common standard SQL, PostgreSQL, MySQL, and SQLite DML and DDL. Complex stored procedures, vendor-specific administrative commands, and unusual procedural syntax are outside the guaranteed scope.

Will formatting change strings or quoted identifiers?

The tokenizer preserves single-quoted strings, double-quoted identifiers, backtick identifiers, and their escaped quote sequences. Always review highly unusual dialect-specific quoting, especially inside procedural code.

Can I use this tool with SQL containing secrets?

The SQL is formatted locally and is not uploaded or executed. Even so, query logs can contain passwords, access tokens, emails, and customer records, so redact sensitive literals before sharing the formatted result.

Does changing keyword case rename my tables or columns?

No. Case conversion is limited to recognized SQL keywords. Ordinary and quoted identifiers retain their original spelling, as do string values and comments.