❯
❯
SQL
Code Formatting
Formatter Tool

SQL Formatter

Format and beautify SQL online, free and private.

Paste a messy query and turn it into clean, readable SQL in one click. Choose your dialect, indentation and keyword case, line up clauses in a tabular layout, or minify SQL into one compact line. Works with MySQL, PostgreSQL, SQL Server, Oracle, BigQuery, Snowflake and more. Your code is formatted in your browser and never uploaded, with no sign-up.

100% Free

No Sign-Up, No Limits

19 SQL Dialects

MySQL, PostgreSQL, T-SQL & More

Private & Secure

SQL Never Leaves Your Browser

Beautify or Minify

One Click, Then Copy or Download

0 characters 0 lines 0 B
Result
0 B 0 lines
Settings
Indentation
Minify

Tip: press Ctrl + Enter inside the input box to beautify. You can also drop a file onto the input.

Private by design: your code is formatted in your browser and never uploaded. Protected by Cloudflare Turnstile.

How Do You Format SQL Online?

To format SQL online, paste your query into the SQL input box, upload a .sql or .txt file, or press Sample. Choose your dialect, indentation and keyword case in Settings, then click Beautify SQL. The formatted query appears in the Result box, ready to copy, download or use as input again. Click Minify SQL to compress it to a single line instead.

SQL often arrives as one long line: copied from an ORM log, an error message, a BI tool or a teammate's chat. Long SELECT statements with nested joins and subqueries are hard to read, review and debug when everything is crammed together. A SQL formatter adds consistent line breaks, indentation and keyword case so you can see the structure of a query at a glance and spot mistakes faster.

Everything happens on your own device. The formatter reads your SQL in the browser using the rules of the dialect you pick, then rebuilds it with clean line breaks and indentation. Your queries are not sent to Teasoft or anyone else, so you can safely format production queries, schema scripts and code that contains table names or business logic.

What changes when you format SQL:

Part of your SQLAfter formattingGood to know
KeywordsUPPERCASE, lowercase or as writtenSELECT, FROM, WHERE and JOIN follow the keyword case you choose.
Clauses and joinsOn their own linesEach SELECT, FROM, JOIN, WHERE, GROUP BY and ORDER BY starts a new line.
Column listsOne column per lineLong SELECT lists are easy to scan and compare in code review.
Subqueries and CTEsIndentedNested queries and WITH blocks are indented so you can see each level.
Strings, names and valuesUnchangedQuoted text, table and column names and numbers stay exactly as written.
CommentsKeptComments stay when you beautify. Minify removes them only if you tick Remove comments.

Common reasons to format SQL

What each control does:

ControlWhat it doesWhen to use it
SQL input boxHolds the SQL you want to formatPaste a query or drop a file here. Press Ctrl + Enter to beautify.
Upload, Paste, Sample and ClearAdd SQL from a file, your clipboard or an example, or empty the boxUpload accepts .sql and .txt files. Use Sample to try the tool.
DialectSets the SQL syntax rulesPick your database, such as MySQL, PostgreSQL, SQL Server or Oracle.
IndentationSets the indent sizeChoose 2 spaces, 4 spaces or Tab to match your code style.
Keyword caseChanges how keywords are writtenUPPERCASE is the most common style. Keep as written leaves them unchanged.
LayoutControls how clauses line upTabular layouts align keywords in one column for quick scanning.
AND / ORPlaces logical operatorsStart lines with AND / OR so WHERE conditions are easy to comment out.
Blank lines and new lineSeparate statements and end the output cleanlyAdd 1 or 2 blank lines between queries and tick End with a new line for Git-friendly files.
Beautify SQL and Minify SQLFormats or compresses your queryThen Copy, Download or Use as input. Tick Remove comments to minify further.

Good to know

What You Can Do With This Tool

How to Format SQL (3 Steps)

Add your SQL

Paste a query into the SQL input box, drop or upload a .sql or .txt file, or press Sample to try an example. The character, line and size counters update as you type.

Choose your settings

Open Settings and pick your dialect, indentation, keyword case and layout. Decide where AND / OR go and how many blank lines to leave between queries.

Beautify or minify your SQL

Click Beautify SQL, or press Ctrl + Enter, to format the query. Click Minify SQL for one compact line. Then Copy the result, Download it, or click Use as input to format it again.

Tip: pick your database’s dialect before you format, so special syntax such as backtick identifiers in MySQL, :: casts in PostgreSQL or square brackets in SQL Server is handled correctly. If your query results come back as JSON, tidy them with the JSON Formatter.

Which SQL Formatting Settings Should I Use?

TaskUseWhy
Code review or pull requestBeautify, 4 spaces, UPPERCASEA common team style that makes keywords stand out from table and column names.
Long WHERE clausesAND / OR at the start of the lineEach condition sits on its own line and is easy to comment out.
Scanning large SELECT statementsTabular, left alignedKeywords line up in one column so each clause is quick to find.
Migration or seed scripts1 blank line between queries, end with a new lineStatements stay separate and the file works well with Git.
Embedding SQL in code or JSONMinify SQLOne line is easier to place inside strings, configs and API calls.
Sharing SQL in docs or chatBeautify, 2 spacesCompact indentation keeps lines short on narrow screens.

Getting better results when you format SQL

After you format your SQL

  • Run it. Test the formatted query in your database client to confirm it returns what you expect.
  • Keep your style. Use the same settings every time so your team’s SQL looks consistent.
  • Format related data. Tidy query results or exports with the JSON Formatter or XML Formatter.
  • Clean up the code around it. Format the application code that runs your SQL with the JavaScript Formatter.

Frequently Asked Questions

Paste your SQL into the input box, choose a dialect and your settings, then click Beautify SQL. Copy or download the formatted query from the Result box.

Yes. It is completely free, with no sign-up and no limit on how often you use it.

No. Your SQL is formatted inside your browser on your own device. It is never sent to Teasoft or anyone else.

Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake, Amazon Redshift, Spark SQL, Trino / Presto, IBM Db2, Hive, TiDB, DuckDB, ClickHouse, SingleStoreDB and Couchbase N1QL.

No. Formatting only changes spaces, line breaks and keyword case. Your query returns exactly the same results.

Paste your query and click Minify SQL. Extra spaces and line breaks are removed and the query is placed on one line. Tick Remove comments when minifying to strip comments too.

Yes. Under Keyword case, choose UPPERCASE, lowercase or Keep as written, then click Beautify SQL.

You can indent with 2 spaces, 4 spaces or a tab, and choose whether the output ends with a new line.

It lines up SQL keywords in a fixed-width column, left or right aligned, so clauses such as SELECT, FROM and WHERE are easy to scan.

Yes. Paste a full script with statements separated by semicolons and choose 0, 1 or 2 blank lines between queries.

It is usually a syntax error, such as an unclosed quote or bracket, or syntax from a different database. Check the query and make sure the matching dialect is selected.

Yes. Comments are kept when you beautify. They are only removed when you minify with Remove comments ticked.

Yes. Click Upload or drop a .sql or .txt file onto the input box. Its contents load into the editor, ready to format.

No. It formats your SQL but does not run or validate it against a database. Test the result in your database client.

Yes. It works in Chrome and Safari on Android and iPhone. Paste your query, tap Beautify SQL and copy the result.

No. Everything runs in your web browser. There is nothing to download or install and no account to create.

It works in Chrome, Edge, Firefox, Safari and other modern browsers on Windows, Mac and Linux.

Yes. Press Ctrl + Enter inside the input box to beautify your SQL straight away.

About Teasoft's SQL Formatter

Teasoft's SQL Formatter is a free online tool for beautifying and minifying SQL queries. It supports 19 SQL dialects, including MySQL, PostgreSQL, SQL Server, Oracle, BigQuery and Snowflake, with options for indentation, keyword case, tabular layout and AND / OR placement.

It is made for anyone who works with databases: developers preparing pull requests, data analysts cleaning up report queries, DBAs reading stored procedures, students learning SQL and support teams decoding queries from logs. Paste, format, copy and get back to work.

Your SQL is formatted on your device and is never uploaded. A quick Cloudflare Turnstile check keeps the tool free from bots, and nothing you paste is stored or shared.