SQL Formatter & Beautifier
Clean, indent, and organize complex SQL queries instantly
Make a tangled query readable again
Queries generated by ORMs, copied from logs or squeezed onto a single line are painful to read and worse to debug. The SQL Beautifier rebuilds them with line breaks and indentation so that each clause, column and join sits where you would expect. It is aimed at the moment when you have inherited a query and need to understand it before changing anything.
Beautifying a query
- Paste your statement into the SQL Query box, or press Sample to load a query with joins and a filter.
- Pick the Dialect that matches your database: Standard SQL, MySQL, PostgreSQL, T-SQL (SQL Server) or PL/SQL (Oracle).
- Click Beautify & Format SQL.
- Read the Formatted Query, then use Copy or Download, which saves a file named formatted.sql.
What you get beside the tidy text
Under the result, small badges show the original and formatted character counts and the number of lines. A separate Structure Analysis card gives a quick summary: a basic validation note, the table found after the first FROM, and the number of JOIN keywords in the statement. The validation is superficial: it only looks for a known keyword, matching parentheses and an even number of single quotes.
When it helps
- Reading a long query pulled from a slow-query log or an application trace.
- Understanding a report query written by a colleague who has left the team.
- Comparing two versions of a query in a diff, where consistent layout makes real changes stand out.
- Checking how many joins a generated query really contains.
Details worth knowing
The layout is produced by the open-source sql-formatter library, loaded from a public CDN when the page opens. If that script cannot load, the tool falls back to a simple mode that just starts a new line at major keywords, so output will look plainer. Choosing the right dialect matters for things like backtick names in MySQL or bracketed names in SQL Server. Keywords keep the capitalization you typed, so if you want uppercase keywords, type or convert them first. The primary table detection looks at the first FROM only and will not describe subqueries. Beautifying changes only whitespace, but you should still run the result in a safe environment before relying on it. The work is done in your browser.
Related Tools
Related Tools