SQL Formatter
Format and minify SQL queries instantly. Supports MySQL, PostgreSQL, SQLite, T-SQL and more.
What is a SQL Formatter?
A SQL formatter (or SQL beautifier) takes raw or minified SQL queries and reformats them with consistent indentation, keyword capitalisation, and line breaks, making complex queries dramatically easier to read and review. Unformatted SQL — especially auto-generated ORM queries or legacy stored procedures — can be nearly unreadable as a single line. A good formatter also validates basic syntax, helping catch structural errors before executing the query against a database.
Common Use Cases
- Beautify ORM-generated queries for debugging and performance analysis
- Standardise SQL style across a team's codebase and migrations
- Review stored procedures or views that were written without formatting
- Prepare SQL snippets for documentation, bug reports, or code reviews
- Detect syntax errors in complex multi-join queries before running them
How It Works
This formatter uses the sql-formatter library to parse your SQL into an abstract syntax tree and then serialise it back to text with configurable indentation and keyword case. You can choose the SQL dialect (MySQL, PostgreSQL, SQLite, etc.) to get dialect-specific keyword handling. All formatting runs in your browser — your queries are never sent to a server.
Frequently Asked Questions
Does formatting change how a query executes?
No. SQL is case-insensitive for keywords and whitespace-insensitive. Formatting only affects how the query looks — the database query planner sees the exact same logical structure regardless of indentation.
Why do I need to select a SQL dialect?
Different databases have different reserved words and syntax extensions. Selecting the correct dialect ensures that database-specific keywords (like PostgreSQL's RETURNING or MySQL's LIMIT placement) are handled correctly.
Should SQL keywords be uppercase or lowercase?
Convention favours uppercase keywords (SELECT, FROM, WHERE) to visually distinguish them from table and column names. Most style guides and linters enforce this, though it is purely aesthetic.
Related Tools
JSON Formatter
Format, validate, and minify JSON data instantly.
Regex Tester
Test and debug regular expressions with live match highlighting.
Text Diff
Compare two blocks of text and highlight additions, deletions, and unchanged lines.
JSON ↔ YAML
Convert between JSON and YAML instantly with real-time validation.
Hash Generator
Generate MD5, SHA-1, SHA-256, and SHA-512 hashes instantly.
Base64 Encoder
Encode and decode strings using Base64 encoding.
JWT Decoder
Decode and inspect JSON Web Tokens securely in your browser.
Case Converter
Convert text to camelCase, snake_case, UPPERCASE, kebab-case, and more.
URL Encoder
Encode and decode URLs with percent-encoding instantly.
Cron Parser
Parse cron expressions into plain English and preview next scheduled runs.
UUID Generator
Generate UUID v4 values instantly, with bulk generation and validation.
CSV ↔ JSON
Convert CSV to JSON or JSON to CSV with support for custom delimiters and quoted fields.
Number Base Converter
Convert between decimal, hexadecimal, octal, and binary number bases.
Color Converter
Convert colours between HEX, RGB, HSL, HSV, and CMYK formats.
Powered by sql-formatter: Formatting uses the open-source sql-formatter library with dialect-aware rules for MySQL, PostgreSQL, SQLite, T-SQL, PL/SQL, and BigQuery.
All formatting runs locally in your browser. No SQL is sent to any server.