> sql | format | beautify <
// Format and prettify SQL queries with support for MySQL, PostgreSQL, T-SQL, SQLite
Multi-Dialect Support
Format queries written in standard SQL, MySQL, PostgreSQL, Microsoft T-SQL, or SQLite with dialect-aware keyword handling.
Customizable Indentation
Choose 2-space, 4-space, or tab indentation. Pick UPPERCASE, lowercase, or preserved keyword casing to match your team's style guide.
Format and Minify
Format pretty-prints messy queries; Minify strips comments and collapses whitespace for compact one-line transport.
// ABOUT SQL FORMATTING
How It Works:
The formatter is built on the open-source sql-formatter library, which tokenizes your SQL into keywords, identifiers, literals, and operators using a dialect-specific lexer aligned with ANSI SQL-92 and SQL:2016 reserved words. It then walks the token stream and emits a structured layout: clauses on their own lines, lists indented under each clause, and keywords cased to your preference. Minification reverses the process, stripping comments and collapsing whitespace.
Example:
select * from users u join orders o on u.id=o.user_id where u.active=1 -> SELECT * FROM users u JOIN orders o ON u.id = o.user_id WHERE u.active = 1
Common Use Cases:
- >Clean up generated or pasted SQL before code review
- >Make complex JOIN and CTE queries readable
- >Standardize keyword case across a project
- >Compare two query versions side by side after formatting
- >Compact queries into a single line for embedding in code
>> frequently asked questions
Q: Which SQL dialects are supported?
A: Standard ANSI SQL, MySQL, PostgreSQL, Microsoft T-SQL, and SQLite. Each dialect adjusts keyword recognition and quoting conventions (for example backticks for MySQL identifiers, square brackets for T-SQL bracketed names, and dollar-quoted strings for PostgreSQL). Pick the closest match and the output will use the right reserved words and identifier delimiters for your target engine.
Q: Does it execute or validate my SQL?
A: No. The formatter only rewrites the visual layout of your query. It does not connect to any database, run the query, or check semantic correctness, so it cannot tell you whether a column exists or a join is logically right. It does verify that the syntax can be tokenized, and will surface a parse error if the input is too malformed to layout.
Q: Why does my keyword case change?
A: The Keywords selector controls how reserved words are emitted in the formatted output. UPPER converts words like SELECT, FROM, and WHERE to upper case (the most widely accepted convention), lower forces every keyword to lower case to match a Python or Ruby house style, and preserve keeps the original casing from your input untouched, which is useful when reformatting legacy code.
Q: What does Minify do?
A: Minify is the opposite of beautify: it shrinks the query by stripping single-line and block comments, collapsing all runs of whitespace into single spaces, and removing the spaces around commas, semicolons, and parentheses. The result is a compact one-line query suitable for embedding in JSON config, source code string literals, or shell one-liners.
Q: Is my query data sent anywhere?
A: No. The formatter runs entirely in your browser using the sql-formatter JavaScript library loaded once from a public CDN. Your query text never leaves the page or hits our servers, so the tool is safe to use with sensitive production SQL containing schema names, table structures, or hard-coded credentials you have not yet redacted.