SQL Formatter: Beautify and Indent SQL Queries

Paste a query: one clause per line, 2 or 4 space or tab indentation, and keywords in upper or lower case.

Format a readable SQL query: rules and dialects

The formatter puts each clause (SELECT, FROM, WHERE, GROUP BY…) on its own line, indents columns and conditions by 2 or 4 spaces or a tab, and switches keywords to upper or lower case. It relies on the open-source sql-formatter library and supports 7 dialects: standard SQL, MySQL, PostgreSQL, T-SQL, PL/SQL, SQLite and BigQuery. Processing happens in the browser; the query is not sent anywhere.

Available settings

  • Dialect: sets which keywords and syntax are recognised (brackets [dbo].[table] in T-SQL, backticks in MySQL, ::int casts in PostgreSQL).
  • Indentation: 2 spaces, 4 spaces or a tab.
  • Keyword case: upper (default), lower or unchanged.
  • Identifier case (tables, columns, aliases): unchanged by default; the library itself labels this option experimental.

Example

One-line input: select u.id, count(*) as nb from users u join orders o on u.id = o.user_id where o.status = 'completed' group by u.id

Output in standard SQL, 2 spaces, upper-case keywords:
SELECT
u.id,
count(*) AS nb
FROM
users u
JOIN orders o ON u.id = o.user_id
WHERE
o.status = 'completed'
GROUP BY
u.id

The function name count keeps its case; only keywords change. Quoted strings and comments are kept as they are.

Limits

  • The formatter lays out the query without running or validating it: a missing column or wrong join goes unnoticed.
  • Syntax from another dialect causes a parse error, for example [dbo].[t], @p or ::int in standard SQL. The tool then shows the message and copies your text unchanged: pick the right dialect.
  • Procedural blocks (BEGIN … END, stored procedures) are split poorly.

To turn a table into a C#, Java or TypeScript class, use the SQL to code tool; this one only formats.

Sources and dates: sql-formatter library version 15.8.2 installed in the project (declared dependency ^15.3.0), whose documentation flags the identifier case option as experimental (checked 14/10/2026).

Frequently Asked Questions

Why does the SQL formatter show a parse error?

The query contains syntax the selected dialect does not recognise: SQL Server brackets [dbo].[t] or @p variables, or a PostgreSQL ::int cast in standard SQL. Select T-SQL, PostgreSQL or your database's dialect and the error goes away. While the error remains, the tool copies your text unchanged.

Should SQL keywords be written in upper case?

SQL engines ignore keyword case: select and SELECT run the same. Upper case is a readability convention that sets keywords apart from table and column names. The tool uppercases them by default, with lower-case and unchanged options.

Does the formatter check that my query is correct?

No: it splits and indents the text without connecting to a database. A misspelt column, a missing table or a join that multiplies rows goes unnoticed. Always test the formatted query on your database before deploying it.

Which indentation should I use for SQL?

The tool offers 2 spaces, 4 spaces or a tab. Two spaces keep long queries compact; four spaces stand out better in code review tools. What matters most is that the whole team uses the same setting so diffs stay readable.

Is this tool really free?

Yes, all tools on Kristools are 100% free and accessible without registration.

Is my data protected?

Yes. All processing is performed directly and securely inside your browser. No personal data is sent to our servers.