Logo

MonoCalc

/

SQL Prettier

Programming
Runs entirely in your browser
Your query is tokenised and re-printed locally. Nothing is uploaded, logged or sent to a server, so SQL carrying production table names, schema structure or literal values is safe to paste.

Load a sample:

Standard SQLUPPERCASE keywords2 spacestrailing commasstandard layout
Formatted
10 lines out, +16 characters (+26.7%).

SQL query

Formatted SQL

Input

60 chars

1 lines · 60 B

Output

76 chars

10 lines · 76 B

Size delta

+16

+26.7%

Statements

1

SELECT

Query structure

Simple

Nesting depth

0

Tables & columns

Tables

users

Columns projected

id, name, email

About This Tool

SQL Prettier: format, beautify and minify SQL in your browser

SQL rarely arrives tidy. It comes out of an application log as a single 900-character line, out of an ORM’s debug output with aliases like t0 and t1, or out of a BI tool’s “view generated SQL” panel with no line breaks at all. Add random casing — Select … FROM … where — and three levels of nested subqueries, and simply reading the query becomes the hard part. This SQL formatter takes that mess, tokenises it, and re-prints it as clean, consistently indented SQL.

Nothing leaves your machine
Most online SQL beautifiers POST your query to a remote endpoint. That is a hard no when the query carries production table names, schema structure or literal values. This one is JavaScript running in your own tab, which is what makes it safe for work queries.

How the formatter decides where the lines go

The tool runs a tokenise → print → refine pipeline. First the query is split into tokens: keywords, identifiers, numbers, operators, single-quoted strings, dollar-quoted bodies, and --, # and /* */ comments. Then a clause-aware printer emits those tokens, giving each top-level clause its own line and opening an indent level at every (. Finally the optional refinements run — leading commas, alias alignment, one column per line, print-width wrapping.

The property that matters is that only the whitespace between tokens changes. String literals, dollar-quoted function bodies and comment text are opaque to the printer, so a formatted query returns exactly what the original did. A literal containing -- is not mistaken for a comment, and a comment containing a quote does not swallow the rest of the statement.

Dialects, and why they change the output

Fourteen dialects are supported: Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Db2, Hive, Spark SQL and Trino/Presto. The dialect controls two things that a formatter cannot guess: the reserved-word list and the identifier quoting rules. T-SQL quotes with [square brackets], MySQL with backticks, and PostgreSQL with "double quotes" — each is preserved verbatim and never re-cased. PostgreSQL :: casts and $$ … $$ bodies survive intact, as do BigQuery’s backtick-qualified project.dataset.table names.

If you are not sure which dialect a query came from, the tool scores the syntax it finds — brackets and GETDATE() point at T-SQL, QUALIFY at Snowflake, ROWNUM and NVL() at Oracle — and offers the best guess as a one-click switch.

Team style: casing, commas and the river

Keywords, functions and data types each get their own casing control, so uppercase keywords with lowercase function names is a setting rather than a manual edit. Identifier case is deliberately separate and defaults to Preserve.

Re-casing identifiers can break a query
SQL keywords are case-insensitive, but a quoted identifier is case-sensitive on PostgreSQL and BigQuery. Changing identifier case can point the query at an object that does not exist, which is why Preserve is the default and the tool warns you when you move away from it.

Leading commas put the separator at the start of the next line rather than the end of the current one. The payoff is diff noise: adding a column to a trailing-comma SELECT list touches two lines, because the previously-last column gains a comma. With leading commas it touches one. Tabular (or “river”) layout right-aligns clause keywords in a fixed gutter so the query body forms a clean vertical channel — the house style at many analytics teams.

Minify, and check-only diff

Minify runs the pipeline in reverse: the query is normalised first, then collapsed to a single line for embedding in a string literal, a config file or a one-line CLI invocation, with a character-count and percentage readout alongside. Because a -- comment would swallow everything after it on a single line, kept comments are rewritten as /* */ blocks rather than silently breaking the query.

Check-only mode formats the query and shows a unified diff instead of just the result, with added and removed line counts. It reports “already formatted” when nothing would change, which makes it a quick manual pre-commit check that a pull request really is whitespace-only.

Reading the query back

Alongside the formatted output the tool reports what it found: the number of statements, the CTEs by name, joins broken down by type, subqueries, window functions, CASE expressions, set operations, and the maximum parenthesis nesting depth. Those counts come from the token stream, not a regular expression over the raw text, so the word JOIN inside a string literal is never counted. Past a depth of about three, lifting the inner queries into CTEs almost always reads better than nesting them further. A table and column inventory and a CSV export of the metrics round out the analysis.

Frequently Asked Questions

Is the SQL Prettier free?

Yes, SQL Prettier is totally free :)

Can I use the SQL Prettier offline?

Yes, you can install the webapp as PWA.

Is it safe to use SQL Prettier?

Yes, any data related to SQL Prettier only stored in your browser (if storage required). You can simply clear browser cache to clear all the stored data. We do not store any data on server.

How does this SQL formatter work?

Your query is tokenised in the browser into keywords, identifiers, string literals and comments, then re-printed from that token stream with one clause per line at the indent its parentheses imply. Because only the whitespace between tokens changes, every string literal, dollar-quoted body and comment comes back byte-for-byte identical.

Is my SQL uploaded anywhere?

No. The formatter is JavaScript running inside your own browser tab - there is no server round-trip and no logging of what you paste. That is what makes it safe for queries that carry production table names, schema structure or literal values.

Which SQL dialects are supported?

Fourteen: Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Db2, Hive, Spark SQL and Trino/Presto. Each brings its own keyword set and identifier quoting, so T-SQL square brackets, MySQL backticks and PostgreSQL casts and dollar-quoted bodies all survive formatting intact. The tool can also guess the dialect from the syntax it finds.

Will formatting change what my query returns?

Not with the default settings. Only whitespace and keyword casing change, and SQL keywords are case-insensitive. The one setting that can matter is identifier case, which is why it defaults to Preserve: on PostgreSQL and BigQuery a quoted identifier is case-sensitive, so re-casing it can point the query at a different object. The tool warns you when you change it.

Why are my table and column names not uppercased?

Identifier case defaults to Preserve deliberately. Keywords, functions and data types have independent casing controls that are safe to change, but table and column names are left exactly as you wrote them unless you opt in, because re-casing a quoted identifier can break the query on a case-sensitive dialect.

Can I format a whole migration file?

Yes. Paste or drop a multi-statement script and each semicolon-separated statement is formatted in turn, with a configurable number of blank lines between them. DDL such as CREATE TABLE, ALTER TABLE and CREATE INDEX is handled alongside DML, and the tool reports how many statements it found.