Skip to content
DeviceCheckHub

SQL Formatter

Paste a query and get it back neatly indented, with keywords in the case you choose: a SQL beautifier for 20 dialects, from MySQL and PostgreSQL to SQL Server, Oracle and BigQuery. Mistakes are shown with the exact line and column, and every result is checked so that only the spacing and letter case change.

Paste or open SQL and it is formatted here. Nothing is uploaded.

  • Notes about the result appear here, such as which dialects read your SQL.

How to format SQL

  1. Paste your query or script into Your SQL, or press Open a file to load a .sql file. You can also drag a file onto the box, or press Example to see a messy query tidied up.
  2. Choose your database under Dialect. Standard SQL works for most simple queries; the dialect matters for quotes, comments, parameters and keywords that only one database has.
  3. The result appears on the right while you type. Pick the case for keywords, functions, data types and names, the indentation and the layout until it looks the way your team writes SQL.
  4. Press Copy result or Download. Use result for my text moves the result into the left box so you can keep editing it.

Checked so the meaning never changes

A formatter should only move spaces and line breaks and change the case of keywords. In rare cases a formatter can get more than that wrong, such as splitting the shift operator << into < <, or an arrow -> into - >. Each of these changes what the query does, and neither is easy to spot by eye.

So every result here is checked. Your SQL and the result are both read with the rules of your dialect: strings, quoted names and comments must be exactly the same, and every other character must come back in the same order. Where the formatter split an operator or name, it is put back together; where two parts were joined, a space is kept. The notes tell you when that happened. When the result passes, the notes say: Checked: only spaces, line breaks and letter case changed.

Twenty SQL dialects

SQL is a standard, but every database adds its own pieces. The formatter knows the rules of each of these, so it does not mistake one database's syntax for an error:

The options

The most common SQL mistakes

Tips

Your queries stay on your device

SQL often shows table names, customer data and sometimes passwords, so everything happens in your browser: the reading, checking and formatting all run on your own computer or phone, and nothing is sent to this website or anyone else. The page remembers your latest text and settings in your browser on this device so they survive a reload. Clear removes the text, and clearing the site’s data in your browser removes everything.

Frequently asked questions

Is my SQL uploaded to a server?

No. The formatter runs in your browser, so the queries you paste or open are never sent anywhere. That makes it safe for SQL with table names, customer data or passwords in it. The page keeps your last text on this device so it is still there after a reload; press Clear to remove it.

Which SQL dialects does it format?

Twenty: Standard SQL, PostgreSQL, MySQL, MariaDB, SQL Server (T-SQL), Oracle PL/SQL, SQLite, Google BigQuery, Snowflake, Amazon Redshift, Spark SQL and Databricks, Apache Hive, Trino, Presto and Athena, DuckDB, ClickHouse, IBM Db2, Db2 for i, TiDB, SingleStore and Couchbase N1QL. Each one knows its own quotes, comments, parameters and keywords, such as backticks in MySQL, square brackets in SQL Server and $$ blocks in PostgreSQL.

Can formatting change what my query does?

It should not, and this tool checks it every time. After formatting, it reads your SQL and the result with the rules of your dialect and compares them: strings, quoted names and comments must be unchanged, and every other character must come back in the same order. Where a formatter would split an operator such as << into < <, the tool keeps it together and tells you. If anything else differs, the notes name the line to look at.

Why does it say my SQL is not valid?

Usually because of a missing comma, bracket or closing quote, or because the SQL is written for another database. The message gives the line and column, and the box on the right marks the spot. When another dialect can read your text, the notes name it: MySQL reads SQL with backticks, for example, but PostgreSQL does not.

Should SQL keywords be upper case?

Databases do not care: SELECT, select and Select all work. Many style guides write keywords in upper case so they stand out from table and column names, and that is the default here. Choose Unchanged or lower case under Keywords if your team does it differently. Names stay the way you wrote them unless you choose otherwise, because some databases, such as MySQL on Linux, keep two table names apart when they differ only in case.

How do I minify SQL to one line?

Choose One line (minified) under Result. Line breaks and extra spaces are removed, with one space kept only where two words or operators would otherwise run together. Comments are left out, or kept in /* */ form when you tick Keep comments, so a -- comment cannot swallow the rest of the line.

Does it format scripts with several statements?

Yes. Paste a whole script: each statement is formatted, a blank line is placed between statements (you can choose none or two), and the counts under the result show how many statements and lines there are. SQL Server GO lines stay on a line of their own, and the body of a PostgreSQL function between $$ marks is kept the way you wrote it.

How big a file can it handle?

A file you open can be up to 5 MB. Everyday queries format while you type; a script of many thousands of lines can take a few seconds, and the page says when it is working.

Last updated · About DeviceCheckHub