Xgenious
developer

Free SQL Formatter — Format & Beautify SQL Queries Online

An SQL formatter takes raw or concatenated SQL and returns it with consistent indentation, uppercase keywords, and aligned clauses — making it readable for code review, documentation, and debugging. Supports standard SQL, MySQL, and PostgreSQL syntax in your browser.

Free — No SignupRuns in BrowserData Never UploadedPopular tool

developer

Format and beautify SQL queries with consistent indentation and keyword casing.

  • Formats SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and ALTER TABLE statements
  • Configurable keyword casing: UPPERCASE, lowercase, or preserve original
  • Subquery-aware: nested blocks indented to their own visual level
  • JOIN formatting with ON conditions broken to their own line
  • SQL minifier mode — collapse to a single line for embedding in code or logs
  • Runs entirely in the browser — no SQL is uploaded or stored
  • Adjustable indent size (2 or 4 spaces) to match team style guides
Features

Everything you need in one SQL Formatter

SQL beautifier

Turns a single-line query into readable SQL with each clause — SELECT, FROM, WHERE, JOIN, GROUP BY — on its own line and columns aligned underneath.

Keyword casing control

Uppercase keywords for the classic SQL look, lowercase them for a modern style, or preserve the original casing — applied consistently across the entire query.

Subquery & join aware

Nested subqueries are indented into their own block, joins break onto new lines with their ON conditions, and CREATE TABLE column lists are aligned.

SQL minifier

Collapse a formatted query back to a single line for embedding in application code, logs, or migration scripts — without changing what the query does.

How It Works

How to use SQL Formatter

01

Paste your SQL

Paste any raw or minified SQL query — SELECT, INSERT, UPDATE, DELETE, CREATE TABLE.

02

Choose dialect

Select MySQL, PostgreSQL, or standard SQL. Toggle keyword uppercasing and indent size.

03

Copy output

The formatted SQL appears instantly. Copy to clipboard for your editor or documentation.

Format Comparison

SQL SELECT clause order

ClausePurpose
SELECTColumns and expressions to return
FROMSource tables, with table aliases
JOIN … ONCombine rows from related tables
WHEREFilter rows before grouping
GROUP BYCollapse rows into aggregate groups
HAVINGFilter groups after aggregation
ORDER BYSort the final result set
LIMIT / OFFSETRestrict how many rows are returned
Troubleshooting

How to fix common syntax errors

Most “invalid JSON” failures come from a small set of mistakes. Paste the failing JSON above, click Validate, and the tool points you at the exact line and column.

Unmatched parenthesesSELECT id FROM (SELECT id FROM users

Count opening and closing parentheses — the formatter highlights the mismatch. Add the missing closing paren before the outer query's semicolon.

Double-quoted strings instead of identifiersSELECT "name" FROM users WHERE status = "active"

In SQL, double quotes denote identifiers (column/table names), not string literals. Use single quotes for string values: WHERE status = 'active'.

MySQL backtick identifiers break in PostgreSQLSELECT `user_id` FROM `orders`

Backticks are MySQL-only. In PostgreSQL, use double-quoted identifiers (`"user_id"`) or unquoted names. Run a global replace before migrating queries across dialects.

Leading comma in SELECT causes parse errorSELECT id , name , email

SQL does not allow a leading comma before the first column. Use trailing commas (comma at the end of each line except the last) — this is ANSI-valid and produces cleaner diffs.

Reserved word used as bare column aliasSELECT COUNT(*) AS count FROM orders

COUNT, ORDER, GROUP, and similar reserved words cause parse errors as bare aliases in strict engines. Quote the alias: AS "count" (PostgreSQL) or AS `count` (MySQL).

Missing semicolon between statements in a scriptSELECT 1 SELECT 2

Most SQL engines require a semicolon to terminate each statement in a multi-statement script. Add a semicolon after each statement — the formatter will preserve it in the output.

FAQ

Frequently asked questions

Standard ANSI SQL, MySQL 5.7+, MySQL 8+, and PostgreSQL 14+ are all supported. All common DML statements (SELECT, INSERT, UPDATE, DELETE, MERGE) and DDL (CREATE TABLE, ALTER TABLE, DROP, CREATE INDEX) are formatted. Dialect-specific syntax — MySQL's backtick identifiers, PostgreSQL's `::` cast syntax, and dialect-specific functions — is preserved without modification.

References

Further reading

Authority documentation and specifications behind this tool.

Have a project in mind?

We turn ideas into production-ready software — SaaS, web apps, mobile, and AI agents. Fixed price. Committed timeline. No surprises.

Let's talk