SQL formatter: tidy, indent and minify SQL online

Paste SQL to lay it out with each clause on its own line, choose upper or lower case keywords, comma style and indent size, or minify it to one line. Works for common SQL such as SQLite, PostgreSQL, MySQL and SQL Server, and runs in your browser.

Keep it one tap away for everyday use.

Bookmark SQL formatter?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

Or install fibub as an app: every tool you open then works offline.

  1. Paste SQL
  2. Choose
  3. Format
  4. Copy
Nothing is uploadedWorks offline once open

Format puts each clause on its own line and indents the lists. Minify removes comments and every space that is not needed. Strings and quoted names are never changed.

Result

 

What it does

This tool takes SQL that is on one long line, or written in a hurry, and lays it out so it is easy to read. Each main clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY and so on) starts on its own line, lists are put one item per line, and subqueries and CREATE TABLE column lists are indented. A second button does the opposite and minifies the query to the shortest form.

It reads the text with its own small tokenizer, so strings, comments and quoted names are left exactly as you wrote them. Nothing you paste leaves your browser. To run the query on sample data, open SQL playground; to see what is in a CSV before you write SQL for it, use CSV profiler or CSV to SQL.

How to use it

  1. Paste your query. The example is already there, so you can see the result straight away.
  2. Pick the keyword case, where commas go and how wide an indent is.
  3. Press Format or Minify, then Copy result or Download .sql.

Several statements separated by semicolons are formatted one after another with a blank line between them.

What each setting does

  • Keywords: UPPER CASE or lower case changes words such as select and from, and function names such as count. “Leave as typed” keeps your own case. Table and column names are never changed.
  • Commas: “At the end of a line” gives a, then a new line. “At the start” gives , b on the next line, a style that makes it easy to comment out one column.
  • Indent: 2 spaces, 4 spaces or a tab for each level.
  • Minify: removes comments and all spaces that are not needed. Spaces stay where two words or numbers meet.

Worked example

The example query is 283 bytes on one line. Formatted with upper-case keywords and a 2-space indent it becomes 20 lines: SELECT with four columns, FROM users u, LEFT JOIN with its ON and AND lines, WHERE with two conditions, GROUP BY, HAVING, ORDER BY and LIMIT 10. Minified it is 267 bytes, about 6% smaller.

FAQs

Does it check that my SQL is correct? No. It only changes the layout. A mistake in the query stays a mistake, so run it in your database or in SQL playground to find out.

Will it work for my database? The layout rules cover the SQL that SQLite, PostgreSQL, MySQL, MariaDB and SQL Server share, including their quoting styles. Very vendor-specific blocks, such as stored procedure bodies, are laid out line by line as best it can and may need a touch by hand.

Is my query sent anywhere? No. It is formatted on your device, and the page keeps working offline once it has loaded.

Why does BETWEEN a AND b stay on one line? The tool knows that this AND belongs to BETWEEN, so it does not start a new line there.

Where the numbers come from

  • fibub's own SQL tokenizer and layout rules, written for this page. It reads strings, quoted names (double quotes, backticks, [brackets]), comments, numbers, variables like @x, :x and $1, and the operators :: || -> and ->>. It lays out text only; it does not check that the SQL is valid for your database.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Read more on the Blog

Last updated 2026-12-05.

Related tools