Format and beautify SQL

Lay out a SQL query with one clause per line. Pick the dialect and keyword case. Nothing is run.

How it works

  1. Paste your SQL
  2. Choose the dialect, keyword case and indent
  3. Copy the formatted query

What the formatter changes

The page lays a query out over many lines. Each major clause, such as SELECT, FROM, WHERE, GROUP BY and ORDER BY, starts on its own line, the columns under SELECT get one line each, and joins and AND or OR conditions are indented under their clause. A query that arrived as one 300 character line becomes a column you can read. Several statements separated by semicolons are kept in order with one blank line between them. Comments are kept. Names, values and the logic of the query are not touched.

Dialect, keyword case and indent

The dialect tells the formatter which quoting and keywords to expect. Pick Standard SQL, PostgreSQL, MySQL, SQLite, T-SQL (SQL Server) or BigQuery. It matters for quoting: MySQL reads backticks around a name, T-SQL reads names in square brackets, and a dialect that does not know a style reports an error at that position. Keyword case can be UPPER, lower or Keep as typed, and it changes only reserved words, never your table or column names. Indent can be 2 spaces, 4 spaces or a tab.

What it does not do

The query is never run. Nothing connects to a database, and no table or column is looked up, so a misspelled column name passes through unchanged. The page does not check whether the query would work. It only reports a problem when it cannot read the text with the dialect you chose, for example an unclosed quote or a missing closing bracket, and then it gives the line and column of that spot with a fixed message. Your query text is not repeated in the message.

Limits and where it runs

The work happens in this tab. The query is not sent to a server, not saved and not put in the page address. Only your choices are remembered in this browser. The formatting code is a separate download that loads when the page opens. Up to 500,000 characters are handled. Above 100,000 characters the result follows your typing after a short pause, and a very long script can take a few seconds to lay out. Longer text shows a message asking you to split it.

Frequently asked questions

Does it run my query?

No. The text is only laid out. Nothing connects to a database, so it is safe to paste a query that deletes or updates rows.

Which dialect should I choose?

Choose the database the query is written for. If it uses backticks around names pick MySQL, and if it uses [square brackets] pick T-SQL. Standard SQL is a fair choice for plain queries that use only common syntax.

Does the keyword case change my table names?

No. Only reserved words such as select, from and where change case. Table names, column names and text in quotes stay as you typed them.

Why do I get a line and column error?

The formatter could not read the query with the chosen dialect. The usual causes are an unclosed quote, a missing closing bracket, or syntax that belongs to another dialect. Fix the spot named, or switch the dialect.

Can it find a mistake in my query?

Only a mistake in how the text is written, such as a missing bracket. It cannot tell whether a table exists, whether a column name is right or whether the query would return what you want.