SQL Formatter & Beautifier
Paste any SQL query and format it with proper line breaks and keyword casing. Supports SELECT, INSERT, UPDATE, DELETE, JOINs, CTEs, and more. Runs entirely in your browser.
Developer Tools Cluster
What This Tool Does
Formats and beautifies SQL queries with proper indentation, keyword capitalization, and consistent spacing — entirely in your browser. Supports MySQL, PostgreSQL, SQL Server, SQLite, and standard ANSI SQL.
Who This Is For
- Developers reviewing one-line SQL queries copied from ORMs, logs, or error messages
- DBAs standardizing SQL code style across a team or codebase
- Data analysts making complex queries readable before sharing with colleagues
- Anyone copy-pasting SQL from documentation that arrives as a dense single line
Example: Input: A minified query like select u.id,count(*) from users u join orders o on u.id=o.user_id where o.status='complete' group by u.id having count(*)>5 → Output: A properly indented, keyword-uppercased SQL query that's immediately readable and ready for a code review
How to Format SQL
- Paste your SQL query (or multiple queries) into the input field.
- Select your SQL dialect: SQL Server (T-SQL), MySQL, PostgreSQL, or generic SQL.
- Click Format. The output shows the query with consistent indentation and keyword casing.
- Copy the formatted SQL or use it directly.
The formatter handles SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER TABLE, CTEs (WITH clauses), subqueries, and window functions.
What Good SQL Formatting Looks Like
Unformatted (hard to read):
select u.id,u.name,count(o.id) as order_count from users u left join orders o on u.id=o.user_id where u.created_at>'2026-01-01' group by u.id,u.name having count(o.id)>0 order by count(o.id) desc limit 100Formatted (immediately readable):
SELECT
u.id,
u.name,
COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o
ON u.id = o.user_id
WHERE u.created_at > '2026-01-01'
GROUP BY
u.id,
u.name
HAVING COUNT(o.id) > 0
ORDER BY COUNT(o.id) DESC
LIMIT 100;The structure, JOIN conditions, and filtering logic are immediately visible in the formatted version.
SQL Formatting Conventions
| Element | Convention | Example |
|---|---|---|
| Keywords | UPPERCASE | SELECT, FROM, WHERE, JOIN |
| Table/column names | lowercase or quoted | users, order_id |
| Indentation | 2 or 4 spaces per level | Subqueries indented inside |
| Column list | One per line | Each column on its own line |
| JOIN conditions | Indented under JOIN | ON clause indented |
| CTEs | Each on its own block | WITH cte1 AS (...), cte2 AS (...) |
These conventions are not enforced by the database — SQL is whitespace-insensitive. They are for human readability, code review, and maintenance.
SQL Formatting in Development Workflows
- Code review — formatted SQL is much easier to diff and review. A formatting pass before committing reduces noisy diffs.
- Stored procedures — long stored procedures benefit enormously from consistent formatting. An 800-line procedure with poor indentation is nearly unreadable.
- ORMs and query builders — when debugging ORM-generated SQL, paste the raw query here to read it.
- Documentation — SQL examples in technical documentation should always be formatted for readability.
- Cross-dialect porting — when moving queries between MySQL and PostgreSQL, formatting helps identify dialect-specific syntax.
SQL Development Workflow
SQL formatting is part of a complete SQL development and analysis workflow:
- Generate PIVOT queries and format them for code review
- Generate deduplication queries — deduplicate before formatting and optimizing
- Build date spine queries for time series analysis
- Convert timestamp values used in your SQL date filters
- Format JSON columns returned by SQL queries
Related Tools
- Got JSON query results to analyze? Export them to CSV for spreadsheet use. → export query result JSON to CSV
- Documenting a database schema or query library? Convert Markdown SQL docs to HTML. → publish SQL documentation online
- Passing a SQL query as a URL parameter? URL-encode it to prevent malformed requests. → URL-encode SQL queries for API calls
- Implementing a query cache? Hash each SQL query with MD5 or SHA-256 as the cache key. → fingerprint SQL queries for caching
- Building SQL-backed JWT authentication? Use the JWT Decoder to inspect and debug tokens. → decode tokens in SQL authentication contexts
- Parsing SQL strings? Test your regex patterns against SQL query samples. → match SQL patterns with regex
- Building a data dashboard? Minify your CSS with the CSS Minifier. → minify front-end assets for data apps
- SQL queries that output HTML? Beautify the output with the HTML Formatter. → format HTML in SQL-generated reports
- SQL queries sometimes return hex-encoded IDs. Convert them to decimal with the Number Base Converter. → convert hex IDs from SQL results
- Storing color values as hex in a database? Convert them to RGB for display with the RGB Converter. → decode hex color values stored in SQL
- Writing SQL connection code? See the syntax in VB.NET by converting from C#. → see SQL connection code in C# vs VB.NET
- Migrating a VB.NET data access layer? Translate SQL connection and query code to C#. → convert VB.NET database code to C#
- Setting up SQL Agent jobs or scheduled queries? Verify the cron expression with the Cron Parser. → schedule SQL maintenance jobs
Related Guides & Tutorials
Writing Readable SQL: A Guide to Formatting Queries for Teams
Consistent SQL formatting prevents bugs, speeds up code review, and makes queries easier to maintain.
GuideJSON vs XML vs CSV: Which Data Format Should You Use?
A practical breakdown of when to reach for JSON, XML, or CSV — with real-world API and data pipeline examples.
Frequently Asked Questions
WITH name AS (...)) are fully supported. The formatter will indent the CTE body and align multiple CTEs consistently.