SQL Formatter
Format, beautify, and minify SQL with syntax highlighting
Free Online SQL Formatter — Beautify and Minify SQL Queries
SQL queries can become hard to read quickly. A single line with multiple joins, subqueries, and conditions is difficult to debug and even harder to review in a team. Formatting your SQL is not just a style preference — it is a productivity tool. Clean, indented SQL is easier to understand, faster to debug, and less likely to contain hidden errors.
This free SQL Formatter takes any SQL query and reformats it with proper indentation, uppercase keywords, and logical line breaks. Major clauses like SELECT, FROM, WHERE, JOIN, GROUP BY, and ORDER BY each get their own line. Sub-clauses like AND, OR, and ON are indented one level. Column lists in SELECT statements are split across lines for readability. The output panel uses syntax highlighting with colour-coded keywords, strings, numbers, and comments.
Need the opposite? Switch to Minify mode to compress your SQL into a single line — perfect for embedding in code or reducing payload size. Copy the result, download it as a .sql file, or use the built-in sample queries to test. Everything runs in your browser. No data is sent to any server.
How the SQL Formatter Works
Keyword Uppercasing
All SQL keywords are automatically converted to uppercase. SELECT, FROM, WHERE, JOIN, and over 100 other keywords are recognised and capitalised.
Clause Line Breaks
Major clauses get their own line: SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, JOIN, ON, UNION, and more. This creates a clear visual structure.
Smart Indentation
Sub-clauses like AND, OR, WHEN, THEN, and ELSE are indented one level. Column lists in SELECT are expanded with consistent indentation.
Syntax Highlighting
The output panel shows keywords in blue, strings in green, numbers in pink, and comments in grey. This makes it easy to scan the query at a glance.
Minify Mode
Compress any SQL query into a single line. Whitespace is removed, and parentheses/commas are tightened. Perfect for embedding in application code.
Sample Queries
Four built-in sample queries cover common patterns: SELECT with JOIN, subquery, CREATE TABLE, and INSERT. Click any sample to load it instantly.
