SQL Formatter
This free online SQL formatter beautifies SQL statements with proper indentation and uppercased keywords — and can minify them back down to a single line.
All tools on this site run entirely in your browser locally. No data is uploaded to any server.
Features:
- Beautify: Re-indent SQL with consistent spacing and uppercased keywords
- Adjustable indent: Switch between 2, 3 or 4 spaces at the top, default 2, and your choice is remembered for next time
- Minify: Strip comments and extra whitespace into a single line, keeping required spaces and leaving string literals untouched
- Dialects: Supports MySQL, PostgreSQL, Oracle PL/SQL, SQL Server T-SQL, Hive, Snowflake and more
FAQ:
- Q: Do I need to click Format, and why does it read the right pane?
A: No: typing in the left pane reformats into the right pane automatically. Format reads the right pane instead, so you can tidy text you've edited there or expand a minified one-liner back into indented SQL. Copy, Minify and Save use the right-hand text too. - Q: Can I change the indentation or keyword case?
A: The Indent dropdown at the top offers 2, 3 or 4 spaces, with 2 as the default, and your choice is saved locally for your next visit. Changing it reformats the right pane from the text on the left, so manual edits on the right are replaced. Keywords are always uppercased and statements separated by two blank lines; those cannot be changed. Settings only offers Line Wrap, which affects how long lines are displayed, not the output. Your dialect, Line Wrap choice and divider position are stored locally too. - Q: What does Minify change, and can I undo it?
A: It removes -- and /* */ comments and collapses whitespace into one line, keeping a space only where two tokens would otherwise run together. Quoted strings, double-quoted identifiers and backtick names are copied verbatim, and keyword case stays as it is. Click Format to expand the SQL again, but comments removed by minifying are gone. - Q: Why did the right pane show an error stack instead of SQL, with the highlighting gone?
A: The formatter couldn't parse the input, so the pane shows its error message and switches off SQL syntax highlighting; a hint also appears next to the dialect dropdown. It's usually a syntax error or syntax that belongs to another dialect. Fix the statement or pick a different SQLType and the formatted output returns. - Q: Which dialects are supported, and does the choice affect Minify?
A: The SQLType dropdown offers 19 dialects, from Standard SQL to MySQL, PostgreSQL, Oracle PL/SQL, SQL Server T-SQL, SQLite, BigQuery, Hive, Spark and Snowflake. Selecting one reformats immediately. Minify uses its own scanner rather than the formatter library, so the dialect setting has no effect on it.
Common uses:
- Cleaning up unformatted SQL for easier reading and debugging
- Compressing SQL to reduce transfer size
- Reformatting queries copied from logs or generated code