SQL Formatter

Paste a query to lay out SELECT, INSERT, UPDATE, DELETE and CREATE statements with joins, subqueries and clear indents.

Deze inhoud is in het Engels.

Uitgewerkte voorbeelden

Laying out a short query

select id, name from users where active = 1 and role = 'admin' order by name

SELECT id, name FROM users WHERE active = 1 AND role = 'admin' ORDER BY name

Each main clause starts on its own line, and conditions joined with AND sit underneath the WHERE clause; exact spacing may vary slightly between formatting choices.

Keeping keyword case as typed

A query with lowercase keywords, with the keep as typed option chosen

Keywords keep their original case, while the clauses are still laid out on their own lines.

Choose keep as typed when the team uses a different keyword style from the default.

Over SQL Formatter

A SQL formatter takes a query that has been squeezed onto one line, or typed in a hurry, and lays it out so each part is easy to find. This tool puts every major clause such as SELECT, FROM, WHERE, GROUP BY and ORDER BY on its own line, indents the columns, tables and conditions beneath it, and gives each join and each AND or OR condition a separate line. The result is a query you can read from top to bottom and compare with another version.

It works with the statements people write most often: SELECT with joins, subqueries and CASE expressions, INSERT with several rows, UPDATE, DELETE and CREATE TABLE with its column list. Text in quotes, quoted names and comments are kept exactly as typed, and only spacing, line breaks and the case of keywords change. You can choose upper case, lower case or leave keywords as written, and pick two spaces, four spaces or a tab for each level of indent. It also copes with several statements pasted together.

Zo gebruikt u SQL Formatter

  1. Paste your SQL into the input box, or open a .sql file.
  2. Choose upper case, lower case or as-typed keywords.
  3. Pick an indent size of two spaces, four spaces or a tab.
  4. Copy the formatted query, or download it as a file.

Veelvoorkomend gebruik

  • Tidying a query copied from a log or from a single-line string in code
  • Making a long report query easier to review with a colleague
  • Preparing a query for documentation or a pull request
  • Checking the structure of joins and nested subqueries

Veelgestelde vragen

How do I format a SQL query?

Paste the query into the box and the formatted version appears straight away. Each clause starts on its own line, columns and conditions are indented below it, and joins and subqueries are laid out in blocks. Copy the result or download it as a .sql file when you are happy with it.

Will formatting change what my query does?

No. Only spaces, line breaks and the case of recognised keywords are changed. Text inside quotes, quoted table and column names, numbers and comments are copied exactly as you typed them, so the query returns the same results after formatting as it did before.

Which kinds of SQL does it understand?

It is built for the everyday parts shared by most databases: SELECT, INSERT, UPDATE, DELETE and CREATE TABLE, with joins, subqueries, CASE expressions, window functions and common table expressions. Features that belong to one database only are passed through as ordinary words, so the output stays correct but may be laid out more simply.

Can I keep my keywords in lower case?

Yes. Use the keyword case option to choose upper case, lower case or keep as typed. Upper case is the usual style because it helps keywords stand out from table and column names, but the choice makes no difference to how the database reads the query.

What happens to comments in my SQL?

Comments that start with two dashes and comments wrapped in slash and star marks are kept. A comment that sits at the end of a line stays at the end of that line, and a comment on its own line stays on its own line at the current indent, so your notes are never lost.