SQL formatter
Format SQL queries for PostgreSQL, MySQL and more.
Try
About this tool
- Runs in
- your browser
- Your input sent to our servers
- Nothing
- Kept on this device
- nothing
More in the privacy policy.
How to use it
- 01Paste a query or a script with several statements, open a .sql file or drop one on the page. Or pick one under Try.
- 02Choose the dialect your database speaks, the keyword case and the indent. The formatted SQL appears as you type. Tick Minify to put it on one line, or Remove comments to take the comments out.
- 03Copy the result or download it as a file.
Related tools
Questions
Which databases does it understand?
Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake, Redshift, Spark, Trino / Presto and Db2. Choose the one you use: each knows its own syntax, such as PostgreSQL’s $1 parameters and :: casts (SELECT $1::INT), MySQL’s backticks and SQL Server’s [brackets].
Does it change what the query does?
It’s meant not to. It changes spaces, line breaks and, if you choose, the case of keywords and data types; string literals and quoted names are kept as written, and so are comments unless you choose Minify or Remove comments. Before showing a result it checks that every other character is unchanged, and keeps a function joined to its bracket; if that check fails, it shows an error instead of a result.
What do Minify and Remove comments do?
Minify puts the SQL on one line, with spaces inside strings, quoted names and comments left alone. A -- comment would hide the rest of that line, so it becomes a /* */ comment (select a -- note, then from t on the next line, gives SELECT a /* note */ FROM t), or keeps its line break when its text can’t go inside one. Remove comments takes out -- and /* */ comments (and # in MySQL, MariaDB and BigQuery), but keeps optimizer hints (/*+ … */) and MySQL’s /*! … */, which the database reads as code. Both are checked like formatting: the result must have the same code, strings and names as the input.
Why does it say the SQL ends too early?
The formatter reads the SQL to lay it out, so it points out an unclosed bracket, a quote that isn’t closed or a clause that stops halfway, with the line and column. Fix it there and the formatted result appears.
Is my SQL sent anywhere?
No. It’s formatted in your browser, and a file you open is read there too. It isn’t sent to our servers, put into the page address or saved.