SQL Formatter
Format SQL queries.
About this tool
Paste a one-line SQL query and get it back readable. Each clause starts a new line, selected columns are listed one per line, JOINs line up, AND and OR conditions are indented and subqueries are nested. String literals are left as they are.
How to use
How it works
The query is tokenised so strings and comments are protected, then clause keywords such as SELECT, FROM, WHERE, GROUP BY, ORDER BY and every JOIN start a new line. Commas in SELECT, SET, GROUP BY and ORDER BY lists break lines, AND and OR in WHERE are indented, and a SELECT inside parentheses is indented one level.
Worked example
A filtered query
- Input
- select id, name from users where active = 1 and age > 18 order by name
- Output
- SELECT id, name FROM users WHERE active = 1 AND age > 18 ORDER BY name
- Walkthrough
- Keywords are uppercased and each clause and column gets its own line.
Limitations
- It is keyword based and does not validate SQL or know any one dialect.
- Only the main clause keywords are uppercased; function and column names keep their case.
- CASE expressions and CTEs stay on a single line.
Questions
Does it change my string values?
Does it work for INSERT and UPDATE?
Will it fix invalid SQL?
Is the query uploaded?
Features
- Clause per line
- JOIN and AND/OR indentation
- Subquery nesting
- Strings preserved
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
Learn JSON - Full Crash Course for Beginners
freeCodeCamp.org
Formatted JSON is easier to read once you know the structure.
Watch on YouTubeWhat Is A RESTful API?
Traversy Media
API context for JWT, JSON, and encoding utilities.
Watch on YouTube
- JSON.stringify()
MDN
Pretty-print spacing options that JSON formatters emulate.
- MDN Web Docs
MDN
Primary reference for web APIs these developer tools touch.