1
OneClickUse
Converters Tool

SQL Formatter & Beautifier

Format messy SQL into clean, readable queries — or minify for embedding.

Privacy-first workflows
Fast and simple
100% Free, no signup

Written by Anil Gautam · Updated

What does Format change in a SQL query?

Format squeezes all whitespace into single spaces, then uppercases a fixed list of keywords: SELECT, FROM, WHERE, the JOIN variants, ON, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, CREATE, ALTER and DROP TABLE, WITH, UNION, AS, AND, OR, NOT, IN, EXISTS, BETWEEN, LIKE, IS NULL and the CASE words. Each main clause then starts a new line, and every comma-separated item moves to its own line with a two-space indent. Function names such as count() and words like desc or distinct keep the case you typed.

Paste select name, city from customers where status = 'paid' and total > 500 order by name desc limit 5 and the output puts SELECT on the first line, name and city indented below it, then FROM customers, WHERE status = 'paid' AND total > 500, ORDER BY name desc and LIMIT 5 on lines of their own. Conditions joined by AND or OR stay on the WHERE line. Commas inside function calls and IN lists also break, so IN (1, 2, 3) spreads over three lines.

Can formatting or minifying change what a query does?

Both modes apply pattern rules to the text without parsing SQL, so they cannot tell a quoted string from code. Each one collapses repeated spaces inside strings, turning 'a b' into 'a b'. In Format mode a comma in a string also gets a line break, so WHERE city = 'Delhi, India' comes out with a newline and two spaces after the comma, and the database then looks for different text. Keywords inside strings are uppercased and moved, so '%order from app%' splits into '%order and a new line starting FROM app%'. Quoted names change too: a column called "Order By" becomes "ORDER BY".

Comments are kept in both modes, and a comment that starts with two hyphens runs to the end of its line. Minify puts the whole query on one line, so everything after the first such comment is commented out: with a two-hyphen comment after select id on the first line, the minified query reaches the database as only select id. Format can swallow code the same way when the line after a comment does not start with a clause keyword. Delete those comments or rewrite them in /* */ form first. Outside strings, quoted names and comments, the tool changes only whitespace and keyword case, which SQL ignores.

When should you use Format or Minify?

Format suits a query copied from a log or pasted into a code review. Minify suits a query embedded in a code string or a single-line config value. Neither mode renames anything or checks syntax. To turn a JSON array into INSERT statements, use the SQL option in the JSON Formatter's Convert view.

How it works

How to format SQL

STEP 01
Paste a SQL query.
STEP 02
Pick Format (multi-line, indented) or Minify (single line).
STEP 03
Copy the cleaned output.
You might also need

Related tools

Converters
Roman Numeral Converter
Convert numbers to Roman numerals (1–3999) and Roman numerals back to numbers.
Use now
Converters
Number to Words Converter
Convert numbers to words in Indian (lakh / crore) or international format.
Use now
Converters
Base Converter (Dec / Bin / Hex / Oct)
Convert numbers between decimal, binary, hexadecimal, and octal — all four at once.
Use now
Converters
Cooking Unit Converter
Convert cups, tablespoons, ml, oz, °C, °F, and gas marks.
Use now
Converters
Shoe Size Converter (US / UK / EU)
Convert between US, UK, EU, and centimeter shoe sizes for men and women.
Use now
Converters
Clothing Size Converter
Convert between US, UK, EU, India, and letter sizes (XS-3XL) for men and women.
Use now
FAQ

Common questions