SQL Formatter — Beautify SQL Queries Online
SQL Formatter applies consistent indentation and keyword capitalization to any SQL query, making complex joins, subqueries, and CTEs readable. It supports standard SQL, PostgreSQL, MySQL, and most common dialects.
SQL Formatting Conventions
Formatted SQL capitalises reserved keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, LIMIT) and places each major clause on its own line. Joined tables and WHERE conditions are indented below their parent clause. Subqueries are indented one level deeper than the outer query. This structure makes the query's logic immediately readable: you can scan vertically to see which tables are joined, which conditions filter rows, and in what order results are sorted.
SmartDevBox uses the sql-formatter library, which supports standard ANSI SQL and the most common dialects: PostgreSQL, MySQL/MariaDB, SQLite, T-SQL (SQL Server), and PL/SQL (Oracle). Keywords specific to each dialect (e.g. ILIKE in PostgreSQL, LIMIT in MySQL) are recognised and formatted correctly.
Formatting ORM-Generated SQL
Object-Relational Mappers (ORMs) like Hibernate, SQLAlchemy, ActiveRecord, and Prisma generate SQL at runtime. When you enable SQL logging in development, the output is usually a single minified line with no indentation. Paste that query here to make it readable, then paste it into your database client (pgAdmin, DBeaver, TablePlus) to analyse the execution plan with EXPLAIN.
Stored procedures and triggers in legacy databases are often hundreds of lines of dense, unformatted SQL. Formatting them before a code review reveals the structure — nested CASE statements, correlated subqueries, cursor loops — and makes it much easier to identify performance bottlenecks or logic errors.
Common Use Cases
- Formatting minified SQL from ORM query logs
- Beautifying stored procedures for code review
- Cleaning up SQL exported from database GUI tools
- Making complex multi-join queries readable
Frequently Asked Questions
How do I format a SQL query online?
Paste your SQL query into SmartDevBox. The SQL Formatter auto-detects SQL keywords and applies formatting. It supports SELECT, INSERT, UPDATE, DELETE, CREATE, and most standard SQL statements.
Privacy & Security
This tool runs entirely in your browser using client-side JavaScript. No data is sent to a server — your input never leaves your machine. SmartDevBox has no account system, no usage tracking, and no paid tier. See the Privacy & Security page for full details.
Related Tools
- JSON FormatterFormat and pretty-print JSON instantly in your browser. Validates syntax and shows error location. Free, no sign-up, 100% client-side.
- XML FormatterFormat and indent XML markup instantly in your browser. Validates structure. Free, no sign-up, 100% client-side.