SQL Formatter & Beautifier
Paste a messy query and get readable SQL: one clause per line, upper-case keywords, and indented joins, conditions and subqueries.
How to use the SQL formatter
- Paste one or more SQL statements into the Input box, or press Sample to see a messy query cleaned up.
- Press Format (or Ctrl + Enter). Each clause (
SELECT,FROM,WHERE…) starts a new line, columns and conditions are indented, and subqueries are nested. - Choose UPPER, lower or as typed keywords and 2 spaces, 4 spaces or tabs. Minify puts the query on one line, turning
--comments into/* */so it still runs. - Press Copy and paste the result into your editor, migration or code review.
Everything runs in your browser. Nothing you paste or type is uploaded or saved.
Frequently asked questions
Does the SQL formatter change what my query does?
No. It only changes whitespace and the case of SQL keywords. String values, quoted identifiers, numbers and comments are copied exactly as you wrote them, so the formatted query returns the same result.
Which databases does it support?
It formats standard SQL plus common MySQL and PostgreSQL syntax: backtick and double-quoted names, LIMIT and OFFSET, ON DUPLICATE KEY UPDATE, ON CONFLICT, RETURNING, :: casts, -> and ->> JSON operators, $1 and ? parameters and $$ strings. SQL Server and Oracle queries usually format well too.
Does it check whether my SQL is valid?
Partly. It warns about unclosed quotes, comments and brackets, but it does not run your query or know your tables, so it cannot catch a wrong column name or a missing JOIN condition. Run the query in your database to be sure.