How do I format and beautify SQL online?
Paste your SQL query and click Format to instantly indent and align keywords, clauses, and expressions for readability. The tool supports standard SQL, PostgreSQL, MySQL, and other dialects. Your queries are formatted locally — they never leave your browser.
SELECT u.name, u.email, COUNT(o.id) as orders FROM users u JOIN orders o ON u.id = o.user_id WHERE u.active = true GROUP BY u.name, u.email HAVING COUNT(o.id) > 5 ORDER BY orders DESC;
SELECT u.name, u.email, COUNT(o.id) AS orders FROM users u JOIN orders o ON u.id = o.user_id WHERE u.active = true GROUP BY u.name, u.email HAVING COUNT(o.id) > 5 ORDER BY orders DESC;
SQL Formatter & Beautifier
Format, beautify, and minify SQL queries instantly. Supports SELECT, INSERT, UPDATE, DELETE, CREATE, and more.
About SQL Formatting
This tool formats SQL queries for readability by placing major clauses on new lines and applying consistent indentation. It supports standard SQL syntax including SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, subqueries, JOINs, CASE expressions, and more.
Keyword casing: Choose UPPER, lower, or preserve original casing for SQL keywords. UPPER is the most common convention for readability.
Minify: Removes all unnecessary whitespace and comments, producing compact single-line SQL. Useful for logging, URLs, or reducing payload size.
Supported features: String literals (single/double quotes), backtick-quoted identifiers (MySQL), multi-word keywords (LEFT JOIN, ORDER BY, GROUP BY), inline/block comments, CASE/WHEN expressions, and subqueries with proper parenthesis indentation.
Tips & Best Practices
Capitalize SQL keywords for readability
Writing SELECT, FROM, WHERE, JOIN in uppercase and table/column names in lowercase is the most widely adopted SQL style. It creates immediate visual separation between SQL syntax and your data model. Most formatters default to this convention. Some teams prefer lowercase SQL — consistency matters more than the specific choice.
SELECT * is a maintenance trap
SELECT * fetches all columns, including ones added later that your code doesn't handle. It increases network transfer, prevents covering index optimizations, and breaks when columns are renamed or removed. Always list the specific columns you need. The only exception: EXISTS subqueries where the column list doesn't matter.
CTEs (WITH clauses) make complex queries readable
Instead of nested subqueries 4 levels deep, use Common Table Expressions: WITH active_users AS (...), recent_orders AS (...) SELECT ... This reads top-to-bottom like a story and each CTE can be tested independently. PostgreSQL and MySQL 8+ optimize CTEs as well as subqueries in most cases.
Formatted SQL is easier to spot injection vulnerabilities
Minified or poorly formatted SQL hides string concatenation patterns that signal SQL injection: 'SELECT * FROM users WHERE id = ' + userId. Well-formatted SQL makes these red flags visible during code review. Always use parameterized queries: WHERE id = $1 (PostgreSQL) or WHERE id = ? (MySQL).
Frequently Asked Questions
How do I format SQL queries online?
Should SQL keywords be uppercase or lowercase?
How do I minify SQL for production use?
Related Format Tools
SVG Optimizer
Optimize SVGs by removing metadata, comments, editor data, and unnecessary attributes
JSON Formatter
Format, validate, and minify JSON data instantly
Markdown Preview
Write and preview Markdown with live rendering
XML Formatter
Format, beautify, validate, and minify XML documents instantly