Free • Private • Browser-based

SQL Formatter

Make queries easier to read with dialect-aware indentation and keyword casing. Your SQL stays in this browser and is never executed.

🔒 Processed locallyNo account neededCopy or download

Choose the dialect your query uses.

How to use SQL Formatter

Choose your database dialect, paste a query, select indentation and keyword case, then select Format SQL. Review the result before using it in your own database. Ctrl or Command + Enter also formats the query.

How it works and its limits

Formatting changes presentation, not your database. This tool uses SQL Formatter 15.9.0 and never connects to a database or executes SQL. A successful format is not proof that a query is valid, safe, fast or supported by your server. Stored procedure bodies and custom statement delimiters may not be supported. Input is limited to 200,000 characters and 80 levels of parentheses to keep the browser responsive.

Frequently asked questions

Why does my query fail to format?

Check the selected dialect first. Quoting rules, placeholders and operators differ between databases. The formatter reports parser errors; stored procedures and custom delimiters may need another editor.

Can formatting fix SQL performance?

Readable SQL helps review, but formatting does not optimize a query. Use your database EXPLAIN output and test against representative data.

Are strings and comments preserved?

The formatter retains SQL strings and comments, but whitespace and keyword casing can change. Review generated output, especially database-specific syntax.

Worked example: review a filtered customer list

Select PostgreSQL, UPPERCASE and 2 spaces. Paste the single-line input below and format it. The expected output separates the selected columns, table, condition and sorting rule. The quoted value 'Montréal' stays data; uppercasing keywords does not mean uppercasing every character in the query.

Input
select id, name from customers where city = 'Montréal' order by name;
Expected output with PostgreSQL and 2 spaces
SELECT
  id,
  name
FROM
  customers
WHERE
  city = 'Montréal'
ORDER BY
  name;

Choose the dialect before changing the query

A query copied from a MySQL application may contain backtick-quoted identifiers, while a PostgreSQL query may use double quotes or a cast such as created_at::date. Select the matching database language first. The dialect selector helps the formatter recognize syntax; it does not translate a MySQL query into PostgreSQL or create missing tables.

Use two spaces for a compact review, four when that matches your project, or tabs when your editor expects them. Keyword case is a team convention rather than a performance setting. Keep the original query so you can compare literals, comments and database-specific clauses after formatting.

If the result still looks wrong

  • Check for an unclosed quote or comment before the reported error position.
  • Remove copied terminal prompts and log prefixes; they are not SQL.
  • Try a smaller complete statement when a stored procedure or custom delimiter is unsupported.
  • Use your database's own parser and a suitable test environment to validate behavior. An unknown table can format successfully because this tool has no database connection.

For a longer dialect comparison and a check-before-running workflow, read format SQL for the right dialect.

Examples and practical checks

Understand the result before using it elsewhere.