Skip to main content
SiteIndex
DeveloperReady to use

SQL Formatter

Format SQL statements with indentation, consistent spacing, and readable database query output.

Guide

Interactive workspace

No account required
SQL Formatter

Formats SQL locally without executing queries. Choose your dialect to preserve its strings, comments, and quoted identifiers. Formatting is not full SQL syntax validation.

100% in-browser — your SQL never leaves this device.

Honest limits: the balance check catches unclosed strings, comments and parentheses with a line and column, but this tool does not parse or execute your SQL, so it cannot promise the query is valid for your database.

How to use it

  1. Select the SQL dialect and preferred keyword case.
  2. Paste the statement and select Format SQL.
  3. Review the formatted clauses or resolve the reported lexical error, then copy the output.
What is SQL Formatter?

Format SQL statements with indentation, consistent spacing, and readable database query output.

How it works

A browser-loaded SQL formatter tokenizes the selected dialect, retaining literal, comment, and quoted-identifier contents while formatting clauses and indentation. Choose standard SQL, PostgreSQL, MySQL, SQLite, or T-SQL and upper, lower, or preserved keyword case. Queries are never executed.

Example input and expected output

Input

select id from users order by id

Expected output

SELECT
  id
FROM
  users
ORDER BY
  id
Common uses
  • Read a long SQL query without altering whitespace inside literals.
  • Format PostgreSQL dollar-quoted text or T-SQL identifiers using the matching dialect.
Limitations
  • Successful formatting does not establish full SQL validity, correct permissions, or safe query behavior.
  • Queries are not executed; unsupported syntax may fail even if a database accepts it. Input is capped at 100,000 characters.
Frequently asked questions
Which SQL dialects can I choose?
Standard SQL, PostgreSQL, MySQL, SQLite, and SQL Server T-SQL are available. Select the dialect that matches your query.
Are strings and comments preserved?
Their contents are retained, including spaces within string literals, comments, and dialect-specific quoted identifiers. Formatting changes surrounding layout.
Can I change keyword case?
Yes. Choose uppercase, lowercase, or preserve the original keyword case without changing identifier or literal contents.
Does formatting validate or execute SQL?
No queries are executed. Lexical formatting errors are reported, but successful formatting is not a guarantee of valid SQL or correct database behavior.
Why does a query fail to format?
Check for unfinished strings or comments, select the correct dialect, and review unsupported syntax. Input is limited to 100,000 characters for browser responsiveness.

Related tools