DocumentsImagesMediaPDF Tools

SQL Formatter

Format SQL queries with proper indentation and uppercase keywords.

Drag your PDF here

.pdf · up to 2 GB

FreeNo signupNo watermarkOCR included

Readable SQL, more productive teams

Auto-indentation

Each clause on its own line, subqueries with extra nesting. Immediate readability.

Private

SQL is processed in your browser. Never sent to any server.

Multi-dialect

MySQL, PostgreSQL, SQL Server, SQLite and more. Dialect-specific formatting.

Instant

Results in milliseconds. No waiting, no signup.

Three steps, no hassle

1

Paste your SQL query

Paste SQL directly into the editor. Supports SELECT, INSERT, UPDATE, DELETE, CREATE, and subqueries.

2

Choose the SQL dialect

Select MySQL, PostgreSQL, SQL Server, SQLite or another dialect for precise formatting.

3

Copy the formatted SQL

SQL appears correctly indented with uppercase keywords. Copy with one click.

Got questions?

SQL formatting reorganizes queries by adding consistent indentation, capitalizing keywords (SELECT, FROM, WHERE, JOIN), adding line breaks between clauses, and aligning columns. The result is functionally identical to the original but far more readable, making it easier to review, debug, and maintain complex queries.

Yes. SELECT queries are formatted by expanding each clause onto its own line (SELECT, FROM, WHERE, GROUP BY, ORDER BY) and indenting columns. INSERT queries list fields and values aligned. UPDATE statements separate each SET onto its own line. Subqueries receive an extra indentation level to indicate their hierarchy within the main query.

The convention of writing SQL keywords in uppercase (SELECT, FROM, WHERE) dates back to IBM in the 1970s with the SEQUEL language (SQL's predecessor). On terminals of that era, uppercase visually improved readability by distinguishing language commands from table and column names. Although modern SQL engines are case-insensitive for keywords, the convention persists in SQL style guides from Google, Airbnb, and most data teams.

Subqueries are indented one additional level relative to the containing query. A subquery in a WHERE clause receives 4 or 8 spaces of indentation depending on the chosen style. Correlated subqueries (referencing columns from the outer query) are visually marked with comments in some formatters. CTEs (Common Table Expressions) using WITH are listed one per line before the main query.

Yes. Some ORMs and query caching systems benefit from minified SQL (without unnecessary whitespace or line breaks) for comparing queries by hash or reducing traffic in database protocols. Minified SQL also makes it easier to include queries in code strings without escape characters. SQL minification removes comments, collapses multiple spaces into one, and eliminates line breaks while preserving exact semantics.

SQL history and the art of query formatting

SQL was designed by E.F. Codd in 1970 at IBM as a language for the relational model. The first system implementing SQL was IBM System R (1974–1979), where the language was called SEQUEL (Structured English Query Language). The name was changed to SQL for trademark reasons. In 1986, the SQL-86 standard was published by ANSI, followed by SQL-89, SQL-92 (which added explicit JOINs), SQL:1999 (window functions, regular expressions), SQL:2003 (CTEs, MERGE), and the latest standard SQL:2023.

Query optimization and SQL readability are closely linked. Query plans generated by the database engine depend on how queries are written: a well-indented JOIN immediately reveals if a join condition is missing (producing a costly Cartesian product). SQL style guides from companies such as GitLab, Kickstarter, and Yelp establish that consistent formatting is mandatory for code reviews, as poorly formatted queries in migrations have caused production outages due to errors that are hard to detect visually.

The SQL formatting tool ecosystem includes sql-formatter (npm, by Nikita Galaiko), pgFormatter (Perl, PostgreSQL-specific), SQLFluff (Python, with dbt and Jinja support), and plugins for IDEs like DataGrip and DBeaver. SQL:2023 introduced native JSON data support (JSON_TABLE, IS JSON) and property graphs (SQL/PGQ), expanding use cases beyond traditional relational queries and increasing the complexity that makes automatic formatting indispensable.