How to format SQL queries so they are easy to read
Long SQL on one line is hard to review. SQL formatter lays it out clearly.
Steps
- Paste your SQL.
- Choose keyword case and indent size.
- Copy the formatted query.
Use cases
- Code reviews and documentation.
- Understanding queries from logs.
- Cleaning generated SQL.
Tips
- Formatting never changes results, only layout.
- Put each clause (FROM, WHERE, GROUP BY) on its own line.
- Compare two versions with the Text diff tool.