# SQL formatter

Paste SQL to lay it out clause by clause, or put it on one line. Only spacing and the case of reserved words change: names, strings and comments stay exactly as written. MySQL, PostgreSQL, SQL Server and standard SQL.

Page: https://toolkitnow.org/tools/sql-formatter/

Paste SQL to lay it out clause by clause. Only spacing and the case of reserved words change. The gray text is an example.

## Good to know

### What changes

Spaces and line breaks between the parts of the query, and the case of reserved words such as `select` and `where` and of built-in functions written with a parenthesis, such as `count(*)`. Names, strings, quoted names and comments stay exactly as written. Each result is read again before it is shown: if it does not have the same parts in the same order, no result is shown.

### Names keep their case

A table, column or alias called `date`, `count` or `user` is not changed to upper case: on MySQL on Linux, table names are case-sensitive, so `Orders` and `ORDERS` are different tables, and an alias is the name a column gets in the result.

### Dialects

The dialect decides how text is read: in MySQL `'It\'s'` is one string and `#` starts a comment, while in standard SQL the string ends at `\'` and in PostgreSQL `#` is an operator. Clues such as backticks (MySQL), `::` or `$$` (PostgreSQL) and `[names]` or `TOP` (SQL Server) set the guess. A guessed result is shown only if MySQL, PostgreSQL, SQL Server and standard SQL all read it the same as your SQL; if they do not, choose yours under Options.

### Functions

No space is added between a function and its parenthesis: in MySQL, `count (*)` is not read as the function. A space you wrote there is kept.

### Scripts

`GO` and `DELIMITER //` lines stay alone on their lines, as the tools that read them need; after `DELIMITER`, its mark ends a statement. Statements between `BEGIN` and `END` go one step in.

### Comments

Comments stay on the line they were on. On one line, a `--` comment still ends its line, since everything after it would become part of the comment.

### Open from a link

`?sql=select%20*%20from%20t` opens the page with that SQL; add `&layout=4`, `tab` or `one`, and `&dialect=mysql`, `postgres`, `sqlserver` or `standard`.

Runs in the browser; nothing is uploaded. Part of toolkitnow.org.
