# SQL Formatter

Format and beautify SQL with clause indentation and keyword casing. Strings and comments are never touched. Nothing you paste is uploaded.

Canonical page: https://filetity.com/sql-formatter

## Capabilities

- Free: Yes, with no watermark and no page limit.
- Account required: No. There is no account system.
- Processed on device: Yes. The file is read by your browser and never uploaded. There is no server to send it to.
- Formats: SQL in, any dialect. Formatted SQL out, with keywords upper, lower or left alone, and two or four space indentation.
- Limits: This is a formatter rather than a validator. Every token you type comes back in the original order, and anything it cannot parse is reported with a line and column and printed unharmed.
- Mobile: Yes, on any modern mobile browser. Large files are limited by the memory the phone gives the browser.
- Offline: Yes, once the page has loaded. The tool keeps working with no network connection.

## Questions

### Will it break a query with the word FROM inside a string?

No, and this is the thing worth checking in any SQL formatter. Strings, quoted identifiers in every dialect's style, comments and Postgres dollar-quoted bodies are each read as one token before formatting starts, so nothing inside them is treated as a keyword or re-cased.

### What happens if my SQL has a syntax error?

It still comes back, laid out as well as it can be, with the line and column where the formatter lost the thread. A missing bracket or a CASE with no END is reported rather than thrown, because a formatter that refuses to format the broken query is refusing exactly when you needed to read it.

### Is the output stable if I run it twice?

Yes, and that is tested rather than hoped for. Formatting an already formatted query returns exactly the same text, so putting this in front of a file in version control does not produce a diff every time somebody runs it.

### Which dialect does it assume?

None in particular, which is why it handles backtick identifiers from MySQL, bracketed ones from SQL Server and dollar quoting from Postgres in the same pass. Anything it does not recognise is left as words rather than being reshaped into something it might not be.

### Does it uppercase my column names?

Only if they are reserved words, and that is cosmetic because every database folds unquoted identifiers anyway. Words like name, value, date and type are treated as identifiers rather than keywords, since they are columns far more often than they are anything else.

## Related tools

- [JSON Formatter and Validator](https://filetity.com/json-formatter): Format, beautify, validate and read JSON, and find the line that broke it.
- [XML formatter](https://filetity.com/xml-formatter): Format, beautify and validate XML, with real error positions.
