Format Code Now
/

SQL Formatter for T-SQL, PostgreSQL and MySQL

FV-02

Paste a query, pick your dialect and get it back with each clause on its own line, columns one per line, keywords in uppercase and steady indentation. T-SQL is the default.

Runs in your browser. Nothing is uploaded.

SQL

Result

How to use it

  1. Paste your SQL into the input box, or open a .sql file (up to 5 MB).
  2. Pick the dialect: T-SQL (SQL Server), PostgreSQL, MySQL, SQLite or Standard SQL.
  3. Set the indent to 2 spaces, 4 spaces or Tab, and leave UPPERCASE keywords on or off.
  4. Choose Format to lay the query out, or Minify to squeeze it onto one line.
  5. Copy the result or download it as a .sql file.

What the options do

Dialect tells the formatter which database's syntax to expect, so pick the one that matches your queries. T-SQL is selected by default for SQL Server code. UPPERCASE keywords turns SELECT, FROM and WHERE into capitals; switch it off and keywords keep the case you typed. Indent sets 2 spaces, 4 spaces or a tab. Your choices are remembered in this browser for next time. Comments in the query are kept in the formatted output.

Minify and its limits

Minify removes line comments and block comments, collapses whitespace, and leaves quoted strings and [bracketed] names untouched. It understands T-SQL and standard SQL quoting. It does not handle MySQL backslash escapes or PostgreSQL $$ blocks, so check the result when your query uses those. Because comments are dropped, minify a copy if you want to keep the commented version.

It formats, it does not run or check your query

The formatter only rearranges whitespace and keyword case. It never connects to a database, runs the query or checks that tables and columns exist. It will report an error only when it cannot read the text, for example an unclosed quote or a missing closing parenthesis, and the message gives the line and column. Real table names stay on your machine, because the formatting runs in your browser and nothing is uploaded.

Error messages and what to do

MessageWhat it meansFix
Parse error: Unexpected "'abc" at line 1 column 27.The formatter reached text it cannot read as SQL. A string with no closing quote is a common cause; the quoted text is shown after Unexpected.Close the quote, or pick the dialect your query was written for.
Parse error at token: ) at line 1 column 14A closing parenthesis (or another token) shows up where the SQL does not allow it, such as an extra ) with no matching (.Remove the extra bracket or add the part of the statement that is missing before it.
Parse error at token: «EOF» at line 1 column 17The text ended while the statement was still open, for example an opening ( that was never closed.Add the missing closing parenthesis or the rest of the statement.
Parse error: Unexpected "$$x$$ from" at line 1 column 8.The chosen dialect does not accept that syntax. SQLite and Standard SQL do not accept $$ quoting.Switch the dialect to the one your database uses, then format again.
A ' quote is never closedShown by Minify when a quote opens but never closes. The same message appears for ", ` and [.Add the closing quote or bracket.
A /* comment is never closedShown by Minify when a block comment has no */ at the end.Add the closing */.

Questions people ask

How do I format SQL online?

Paste the query, choose your dialect and click Format. Each clause goes on its own line, columns are listed one per line and keywords are capitalized. Pick 2 spaces, 4 spaces or a tab for indentation. Copy the result or download it as a .sql file.

How do I format T-SQL for SQL Server?

T-SQL (SQL Server) is the default dialect, so just paste your query and click Format. Bracketed names such as [Order Id] and TOP clauses are read correctly. Choose another dialect from the list only if your code is for a different database.

Which SQL dialects does the formatter support?

T-SQL for SQL Server, PostgreSQL, MySQL, SQLite and Standard SQL. Choose the dialect before you click Format, because each one reads quoting and keywords a little differently and a query written for one can fail to parse in another.

How do I minify SQL?

Click Minify. It strips comments and collapses whitespace so the query fits on one line, and leaves quoted strings and [bracketed] names alone. It does not handle MySQL backslash escapes or PostgreSQL $$ blocks, so check those results.

Can I turn off uppercase keywords in the SQL formatter?

Yes. Untick UPPERCASE keywords and the formatter keeps keywords in the case you typed them. The option is on by default. The indent setting works separately and offers 2 spaces, 4 spaces or a tab.

Is my SQL query uploaded when I format it?

No. Formatting runs entirely in your browser, so queries with real table and column names never leave your machine. There is no sign-up and no ads.

About this tool

Formatting runs entirely in your browser, so queries with real table names never leave your machine. Pick the dialect to match your database. Minify understands T-SQL and standard SQL quoting; MySQL backslash escapes and PostgreSQL $$ blocks are not handled, so check those results.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.