💾 SQL Formatter/Beautifier

💾
Characters: {{ sqlInput.length }}
⚙️
📏
⚡
📤
{{ result.formatted }}
Characters: {{ result.stats.formattedSize }}
📊
Keywords:
{{ result.stats.keywords }}
Lines:
{{ result.stats.lines }}
Tables:
{{ result.stats.tables.join(',') }}
💾
Original: {{ result.stats.originalSize }} chars (~{{ Math.round(result.stats.originalSize / 1024 * 100) / 100 }} KB)
Formatted: {{ result.stats.formattedSize }} chars (~{{ Math.round(result.stats.formattedSize / 1024 * 100) / 100 }} KB)
{{ result.stats.formattedSize > result.stats.originalSize ?'Increase:' :'Decrease:' }} {{ Math.abs(result.stats.originalSize - result.stats.formattedSize) }} chars
💾
⚠️ {{ error }}

ℹ️ About SQL Formatter

SQL (Structured Query Language) is the standard query language for relational databases, with the core language defined by ISO/IEC 9075-2:2023 SQL/Foundation. This SQL formatter turns compressed or inconsistently styled queries into readable database scripts with consistent indentation, keyword casing, JOIN layout, and clause breaks.

Use it as an online SQL beautifier before reviewing a production query, pasting a migration into documentation, comparing ORM output, or sharing a complex SELECT statement with another developer. A query such as select u.id,u.email,count(o.id) from users u left join orders o on o.user_id=u.id where u.active=1 group by u.id,u.email becomes easier to scan when SELECT fields, JOIN conditions, WHERE predicates, GROUP BY columns, and ORDER BY clauses each have a clear shape.

What the formatter adjusts:

  • Pretty-prints SELECT, INSERT, UPDATE, DELETE, WITH, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT-style clauses.
  • Normalizes SQL keyword case while preserving identifiers, string literals, numeric values, comments, and quoted text.
  • Applies spaces or tabs with a chosen indent size for migration files, dashboard queries, stored procedure snippets, and code review diffs.
  • Can keep comments for audit notes or remove them when preparing a compact query example.
  • Adds a trailing semicolon when you want a complete standalone statement for a console, SQL worksheet, or documentation block.

SQL has a shared foundation, but each database also has dialect-specific syntax. Check the relevant vendor reference when a formatted query uses PostgreSQL dollar-quoted strings or casts from the PostgreSQL lexical structure, MySQL backtick identifiers and comments from the MySQL language structure, SQLite conflict clauses from the SQLite SQL language documentation, or T-SQL extensions from the Transact-SQL language reference.

Example formatting flow:

-- input
select p.id,p.title,u.email from posts p join users u on u.id=p.user_id where p.published=1 order by p.created_at desc

-- formatted
SELECT
  p.id,
  p.title,
  u.email
FROM posts p
JOIN users u ON u.id = p.user_id
WHERE p.published = 1
ORDER BY p.created_at DESC;

Dialect and safety limitations:

  • This tool formats SQL text for readability; it does not execute queries, validate permissions, inspect indexes, or prove that a statement is safe.
  • Vendor extensions can be reformatted without being fully understood, so test database-specific syntax in the target engine before deployment.
  • Formatting can expose structure and make suspicious predicates easier to notice, but it is not a SQL injection scanner or query optimizer.
  • Paste only SQL you are allowed to process. Avoid including production secrets, credentials, tokens, or private customer data in example queries.

Common use cases:

  • Beautify SQL generated by an ORM before debugging joins, filters, and sort order.
  • Prepare database migration scripts and seed data for review.
  • Convert one-line log output into readable SELECT, INSERT, UPDATE, or DELETE statements.
  • Standardize SQL snippets for runbooks, tickets, tutorials, and API documentation.
  • Compare query versions more cleanly in diffs after applying consistent indentation.

API Usage Example:

POST /api/tools/webdev/sql-formatter
Content-Type: application/json

{
    "sql": "SELECT u.id,u.name,p.title FROM users u JOIN posts p ON u.id=p.user_id WHERE u.active=1 ORDER BY p.created_at DESC",
    "format": true,
    "uppercase": true,
    "indentSize": 2,
    "indentType": "spaces",
    "compactMode": false,
    "removeComments": false,
    "addSemicolon": true
}
Ready