DevBolt
Processed in your browser. Your data never leaves your device.

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.

Format a compact SELECT query
Input
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;
Output
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;
← Back to tools

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

Pro Tip

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.

Common Pitfall

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.

Real-World Example

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.

Security Note

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?
Paste your SQL query into DevBolt's SQL Formatter and it instantly reformats it with proper indentation, keyword capitalization, and line breaks. The formatter handles SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, JOIN, subqueries, CTEs (WITH), CASE statements, and window functions. It supports standard SQL, PostgreSQL, MySQL, SQLite, and SQL Server syntax. You can switch between formatted (readable) and minified (compact) output. Formatted SQL is essential for code reviews, documentation, and debugging complex queries with multiple joins or nested subqueries.
Should SQL keywords be uppercase or lowercase?
Convention strongly favors UPPERCASE for SQL keywords (SELECT, FROM, WHERE, JOIN) while keeping table and column names in their natural case. This visual distinction makes queries easier to read by separating the SQL structure from the data identifiers. Most SQL style guides and linters (SQLFluff, pgFormatter) enforce uppercase keywords. Modern SQL is case-insensitive for keywords, so both work functionally. However, consistent formatting improves readability across teams. DevBolt's formatter automatically uppercases keywords while preserving your table and column name casing.
How do I minify SQL for production use?
Switch to Minify mode in DevBolt's SQL Formatter to remove all unnecessary whitespace, line breaks, and extra spaces while preserving the query's functionality. Minified SQL uses less bandwidth when transmitted over networks and slightly reduces parsing time. However, unlike JavaScript or CSS minification, SQL minification provides minimal real-world performance benefit because the SQL query parser ignores whitespace. Minification is mainly useful for embedding SQL in code strings, logging compact query representations, or reducing payload size in API responses that include SQL. Keep formatted versions in your source code for readability.

Related Format Tools