SQL Formatter
Format or minify SQL in your browser with indentation and keyword-case options for Standard SQL, MySQL, PostgreSQL, SQLite and T-SQL. Nothing is executed.
Format or minify SQL in your browser with indentation and keyword-case options for Standard SQL, MySQL, PostgreSQL, SQLite and T-SQL. Nothing is executed.
SQL Formatter turns long or messy SQL into clean, consistently indented statements. It handles SELECT, INSERT, UPDATE, DELETE, CREATE and ALTER statements, joins, WHERE, GROUP BY, HAVING, ORDER BY, UNION, CASE expressions and nested subqueries, with a choice of 2 spaces, 4 spaces or tabs and UPPERCASE, lowercase or preserved keywords.
Formatting uses the open-source sql-formatter library, bundled on this site, with dialect options for Standard SQL, MySQL/MariaDB, PostgreSQL, SQLite and SQL Server. Strings, quoted identifiers, comments and placeholders are kept as written. It is a formatter only: it does not validate SQL against a database, optimise queries, execute anything or connect to any database.
No. It only rearranges whitespace and keyword case. It does not execute SQL, connect to a database or confirm the query is valid.
The formatter could not parse the statement — usually because it is incomplete or uses syntax from a different dialect. Try another dialect or fix the statement; your input is never changed.
No. Text inside quotes and comments is kept exactly as written. Keyword casing only applies to SQL keywords.
Positional ? placeholders, numbered $1 placeholders and named :name and @name placeholders.
Line comments (--) are converted to /* … */ so they remain valid on a single line; block comments are kept.
The open-source sql-formatter library (MIT licence), version 15.9.0, hosted on this site rather than loaded from a CDN.