Calcorithmevery number has an answer
πŸ”
All tools β†’
← Developer Tools

SQL Formatter

Format and beautify SQL queries for better readability.

SQL input
Formatted SQL

Why SQL formatting matters

Unformatted SQL is one of the most common sources of bugs and misunderstandings in software development. A 200-character single-line query is nearly impossible to review, debug, or optimise. Well-formatted SQL with consistent indentation, uppercase keywords, and logical line breaks makes the query structure immediately obvious β€” joins, conditions, and subqueries become visually distinct sections rather than an undifferentiated string.

SQL formatting conventions

ElementConventionReason
Keywords (SELECT, FROM, WHERE)UPPERCASEVisually distinguishes SQL syntax from data and identifiers
Column and table nameslowercase or snake_caseConsistent with most database naming conventions
Each clause on a new lineSELECT / FROM / WHERE / ORDER BYMakes query structure immediately readable
Indent subqueries2 or 4 spacesShows nesting depth and query logic
Aliases after AS keywordexplicit AS keywordClearer than implicit aliases; self-documenting
Line up columns in SELECTvertically alignedEasier to scan a long list of columns

Before and after: a real query

BEFORE (unformatted): select u.id,u.name,u.email,o.total from users u inner join orders o on u.id=o.user_id where u.active=1 and o.total>100 order by o.total desc limit 10 AFTER (formatted): SELECT u.id, u.name, u.email, o.total FROM users AS u INNER JOIN orders AS o ON u.id = o.user_id WHERE u.active = 1 AND o.total > 100 ORDER BY o.total DESC LIMIT 10

SQL dialect differences

While the SQL standard (ANSI SQL) defines core syntax, each database system has its own dialect with extensions and quirks. Formatted SQL from one system may not run unmodified in another. The most common differences affecting formatting and syntax:

String quotes: PostgreSQL, MySQL: 'single quotes' for strings SQL Server: N'unicode strings' prefix for Unicode Limit/offset: MySQL, PostgreSQL: LIMIT 10 OFFSET 20 SQL Server: TOP 10 ... (or OFFSET/FETCH NEXT in modern versions) Oracle: ROWNUM or FETCH FIRST n ROWS ONLY Date functions: MySQL: NOW(), DATE_FORMAT() SQL Server: GETDATE(), FORMAT() PostgreSQL: NOW(), TO_CHAR()

Frequently asked questions

Does formatting change my query results?

No. Formatting only adds indentation and line breaks for readability β€” the SQL logic and the results it returns are completely unchanged.

Which SQL dialects does this support?

It works with the standard SQL used by MySQL, PostgreSQL, SQL Server, SQLite and others. Dialect-specific syntax is preserved as written.

Is my SQL sent to a server?

No. Formatting runs entirely in your browser, so your queries and any data in them stay private on your device.

Why bother formatting SQL at all?

Readable, consistently indented SQL is far easier to review, debug and maintain, and it reduces mistakes in complex joins, subqueries and long WHERE clauses.

Related Developer Tools tools

JSON Formatter
Format, beautify and validate JSON data online
Regex Tester
Test regular expressions live
Diff Checker
Compare two texts side by side
HTML Minifier
Minify HTML code to reduce page size and improve load times
CSS Minifier
Minify and compress CSS code to shrink file size and speed up your site
JWT Decoder
Decode and inspect JWT tokens
Cron Parser
Parse and explain cron expressions
Color Picker
Pick colors and get HEX, RGB, HSL values