SQL Formatter
Paste a messy, single-line or inconsistently indented SQL query and get back a readable, consistently capitalized version with each clause on its own line. All formatting happens locally in your browser.
How to Use the SQL Formatter
- Paste your SQL query into the input box, no matter how it's currently indented or capitalized.
- Click "Format SQL".
- Common keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, etc.) are uppercased and major clauses are placed on their own line.
- Copy the formatted result and paste it into your codebase, query tool or documentation.
Why Use This Tool?
Is my SQL query or database schema uploaded anywhere?
No. Formatting happens entirely inside your browser using JavaScript regular expressions — your query text, table names and column names are never transmitted to a server, logged, or stored anywhere. This makes it safe to format queries containing internal schema names or business logic.
How does the formatting logic work?
This is a heuristic, regex-based formatter rather than a full SQL parser. It recognizes a broad list of common keywords (SELECT, FROM, WHERE, JOIN variants, GROUP BY, ORDER BY, HAVING, INSERT INTO, VALUES, UPDATE, SET, DELETE, AND, OR, ON, LIMIT and more), uppercases them for consistency, and inserts a line break before each major clause so the query is easier to scan. It does not build an abstract syntax tree, so extremely complex nested subqueries may not indent perfectly on every line — but the vast majority of everyday queries come out clean and readable.
Does it support all SQL dialects?
The keyword list covers ANSI SQL as well as common MySQL, PostgreSQL and SQL Server syntax used in everyday queries — SELECT statements, JOINs, WHERE/GROUP BY/ORDER BY/HAVING clauses, INSERT/UPDATE/DELETE statements, and basic DDL like CREATE TABLE. Highly dialect-specific functions and syntax are left untouched rather than rewritten, so your query's actual logic is never altered — only its layout and keyword casing.
Who benefits from a SQL formatter?
Developers pasting a query from a slow-query log, analysts cleaning up a report someone emailed them, and anyone reviewing a pull request full of dense, single-line SQL all benefit from turning a wall of text into a query they can actually read at a glance.