Format SQL so you can read it

Lay out a long SQL query with each clause on its own line, keywords in capitals and subqueries indented. Strings and comments are never changed.

Read a long query at a glance, without pasting it into someone's server

A query copied out of a log, an ORM or a colleague’s message usually arrives as one long line. This lays it out the way people write SQL by hand, so you can see what it selects, what it joins and what it filters.

Each main clause starts a new line: SELECT, FROM, every kind of JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, and the parts of INSERT, UPDATE and DELETE. The selected columns sit one per line under SELECT. Conditions joined by AND or OR each get their own line, indented under WHERE, except the AND inside BETWEEN, which belongs to its range.

Subqueries and lists

A parenthesis can hold two different things, and they are laid out differently. A subquery, one that starts with SELECT or WITH, is indented one level past the line that opens it and closed on its own line, so a nested query reads like a query. Function arguments, IN lists and column lists stay on the line where they are, with their commas inline, because COUNT(o.id) split over three lines is harder to read, not easier.

What is never changed

Strings in single quotes, names in double quotes, backticks or square brackets, and comments are recognised before anything else and passed through exactly. A column called "order" or a value of 'select * from' stays as written, and keywords are capitalised only where they are keywords. Choose As written to keep your own case everywhere.

The formatter reads the text and does not run it, so it works for any common dialect and needs no connection to a database. It does not check that the query is valid. For quick checks against data, Query a CSV with SQL runs SQL on a spreadsheet in your browser, and the CSS minifier does for stylesheets what this does for queries.

Queries often contain table names, customer IDs and the shape of a schema that is not public. Nothing pasted here leaves your device.

How to format SQL

  1. 1

    Paste one or more SQL statements

  2. 2

    Choose capitals or the case you wrote

  3. 3

    Copy or download the formatted SQL

Everything you need

Clause per line

SELECT, FROM, joins, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT each start a line, with AND and OR conditions indented under WHERE.

Subqueries indented

A query inside parentheses is laid out one level in, under the line that opens it, while function calls and IN lists stay on one line.

Strings untouched

Quoted values, quoted names and comments pass through exactly as written, including any keywords inside them.

Nothing is uploaded, and you can verify it

Processing runs on this device. Open the browser’s Network panel while the tool works and you will see no file upload request to FileGizmo. Temporary previews use local browser URLs, and closing or resetting the page releases them instead of leaving a server copy behind.

No daily limits, no watermarks

Use the tool without a daily task counter, account wall or watermark. Nothing is uploaded, so your device’s memory sets the practical size. Free limits a few repeat-work features, such as 20 images per background batch.

Works on any device, and offline after first load

Use a current browser on desktop, Android, iPhone, or iPad without installing an app. Once this tool and its required assets load, the cached workflow works without a connection. Large jobs are usually more comfortable on a desktop with additional memory.

Frequently asked questions

Which databases does it work with?

Any that use the common SQL clauses, including PostgreSQL, MySQL, SQLite, SQL Server and Oracle. It reformats text rather than running the query, so it does not need to know which database it is.

Will it change my query?

Only its layout and the case of keywords. Values in quotes, quoted names, backtick and bracket names and comments are left exactly as written, and nothing is added or removed.

Does it check that the SQL is valid?

No. It formats what it is given. A query with a typo comes out laid out with the typo in place, which often makes the typo easier to see.

Can it format several statements at once?

Yes. Statements ending in a semicolon are laid out one after another with a blank line between them.

Related guides

Format SQL, minify CSS and read bytes without breaking anythingWhy formatters and minifiers break working code, how strings, comments and UTF-8 bytes trip them up, and how to tidy code without pasting it into a server.