SQL Formatter

Paste a SQL statement to uppercase common keywords and put its top-level clauses on separate lines so it is easy to read and review. Copy or download the result. Everything runs in your browser and your input stays on this device.

What this tool does

Normalize common keyword casing and separate top-level clauses for a readable SQL statement.

What does the SQL formatter change?

It uppercases common keywords and puts top-level clauses on separate lines. It does not run your query or check it against a database. Formatting aims to change presentation. Keep a copy of complex queries and compare literals, parameter markers and clause order before and after.

When to use it

Clear clause boundaries help reviewers distinguish a filter from a result ordering or grouping change.

How to use it

  1. Paste a SQL statement without log prefixes.
  2. Choose Format SQL and inspect the line breaks.
  3. Review the diff against your source and test database-specific syntax in your development environment.

Worked example

Paste the sample query that selects id and email from customers, filters on active and sorts by id. Run the formatter and look for SELECT, FROM, WHERE and ORDER BY on separate lines. Add another condition using a quoted string and verify the string still contains the same characters. Use the formatted result to review a query in a code change where the clause order was hard to scan. When the query came from an application log, remove log prefixes and capture any bound parameters separately before using the result in a database client.

Example input
select id from orders where active = true order by id;
Example output
SELECT id
FROM orders
WHERE active = true
ORDER BY id;

Supported features and limitations

Formats common SQL syntax without running or validating a query against a database. Review vendor-specific procedural SQL before using the result.

Common mistakes and edge cases

SQL dialects differ in how they quote identifiers, represent parameters and delimit procedural statements. Review vendor-specific syntax manually, particularly if your input contains database functions or several nested statements. Formatting changes presentation and does not consult a table definition. A neatly formatted query can still reference an unknown column or have an unintended join. Keep a copy of complex input and review your diff before substituting the formatted version. A useful spot check for a report query is to compare literals, parameter markers and the ordering of clauses before and after formatting. If you need to compare actual results, use a small dataset in your normal development environment.

Frequently asked questions

Does the formatter connect to my database?
No database connection is needed. The tool processes the text in your browser. To verify behavior, use the parser or query tooling for your own database dialect.
Can formatting make a query faster?
Whitespace and keyword case help people read the query. Use your database’s execution plan to assess join strategies, indexes and other factors that affect runtime.
Does it work with SQL Server (T-SQL), MySQL and PostgreSQL?
It formats common SQL syntax across dialects. In the tested SQL Server statement, it kept TOP and @id and split FROM and WHERE onto separate lines. In the tested MySQL statement, it preserved backtick identifiers and split FROM, WHERE and ORDER BY. It also preserves PostgreSQL dollar-quoted strings. The formatter has no dialect-specific parser, so review procedural blocks and other vendor-specific syntax.
Does formatting change what a query returns?
It is meant to change only presentation. For complex queries, compare literals, parameter markers and clause order before and after, and test in your own environment.
Is my SQL uploaded anywhere?
No. The text is processed in your browser and stays on your device.

Related tools

Developer guides