SQL Formatter
Format SQL queries for MySQL, PostgreSQL, SQL Server, SQLite, Oracle, BigQuery and more: clauses on their own lines, indented columns, uppercase keywords.
Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.
How to use the SQL Formatter
- 1 Paste one or more SQL queries.
- 2 Choose the SQL dialect, keyword case and indentation.
- 3 Copy the formatted SQL or download it as a .sql file.
About the SQL Formatter
Long SQL queries on one line, generated by an ORM or copied from a log, are hard to read and review. The SQL formatter puts every clause (SELECT, FROM, JOIN, WHERE, GROUP BY…) on its own line, lists the columns one per line and indents conditions, so the logic of the query stands out.
Choose the dialect of your database so its specific syntax is understood: backtick identifiers in MySQL, :: casts and dollar-quoted strings in PostgreSQL, square brackets and TOP in SQL Server, and so on. Keywords can be written in uppercase (the classic convention), lowercase, or left as they are.
The formatter uses the open-source sql-formatter library and only changes whitespace and the case of keywords; table names, values and comments are kept. It doesn't execute or validate the query against a database, so a query that formats fine can still fail when you run it.
Frequently asked questions
Which databases are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL, IBM Db2 and Trino/Presto.
Does it change my query?
Only the layout and, if you choose, the case of keywords. Identifiers, strings and numbers stay exactly as they were.
Should SQL keywords be uppercase?
It's a convention, not a rule: SQL keywords are case-insensitive. Uppercase keywords make them easy to tell apart from table and column names.
Can I format stored procedures?
Yes, procedural code in PL/SQL and T-SQL is formatted too, though very complex procedures may need some manual touches.