SQL Formatter & Beautifier
Format SQL for 17 dialects with style profiles you can share, check it for six common mistakes with one-click fixes, see which databases' grammar accepts it, and format a folder of files at once. The query never leaves your machine.
Table definitions (CREATE TABLE) for SELECT * expansion and autocomplete
Database Engineering Standard
Layerbit's SQL Formatter is an essential utility for Database Administrators and Backend Engineers. It takes minified, poorly structured, or deeply nested queries and converts them into readable, standardized architecture.
- Syntax Colorization: Intelligent visual parsing separates commands, strings, and parameters.
- Client-Side Processing: Your database structure and query logic never leave your browser. No query or schema is ever uploaded.
Supported Database Engines
Our formatting engine natively supports 16 distinct SQL dialects, ensuring accurate keyword recognition and structural alignment for your specific technology stack.
Relational (RDBMS)
Full support for industry standards including PostgreSQL, MySQL, MariaDB, and SQLite. Handles standard CRUD operations, indexing, and complex joins.
Enterprise Servers
Optimized for proprietary corporate stacks like T-SQL (SQL Server), Oracle PL/SQL, and IBM DB2. Preserves specific stored procedure and variable syntax.
Cloud Data Warehouses
Native parsing for massive analytical queries running on Google BigQuery, Amazon Redshift, Apache Spark, Trino, and Hive.
Advanced Formatting Controls
Go beyond basic indentation. Layerbit provides granular control over how your SQL statements are structured for code reviews and version control.
- Tabular Indentation: Align commas to the left or right of column names. This makes massive
SELECTstatements significantly easier to read and modify. - Query Minification: Click the "Minify" button to compress sprawling SQL files into a single string. This is perfect for embedding raw SQL inside JSON payloads, application code, or YAML configuration files.
- Function Casing: Automatically force standard SQL functions (like
COUNT(),MAX(),COALESCE()) to uppercase while preserving your table and column casing. - Style profiles: Save a set of options (keyword, data type and identifier case, where
AND/ORbreak, line width, dense operators, semicolon on its own line) under a name, switch between profiles, and export them as JSON so a whole team formats the same way. - Checks with fixes: Six checks run as you type:
SELECT *(expanded to the column list when you paste theCREATE TABLE),UPDATE/DELETEwithoutWHERE,NOT INover a subquery that can return NULL, comma joins, unusedDECLAREvariables andLIKE '%…'. Five have a one-click fix; Fix all applies them one at a time. - Selection and many files: Format just the selected statement and leave the rest of the script alone, or choose many .sql files and download them formatted as one zip with a CSV report of syntax errors and checks per file.
- Autocomplete: Paste your
CREATE TABLEstatements and the editor suggests table names afterFROMandJOIN, and column names after an alias and a dot. No database connection is needed. - Persistent State: Your dialect choice, formatting preferences, and active query are saved to local storage. You will never lose your work if you accidentally refresh the browser.
Developer Use Cases
ORM Log Extraction
Take unreadable, single-line queries exported from ORMs (Prisma, Hibernate, Entity Framework) and expand them into formatted architecture to analyze execution plans.
Code Review Standardization
Format massive, deeply nested stored procedures and complex JOIN operations before committing them to your version control repositories to maintain code quality.
Cross-Dialect Migration
Quickly adapt the structural layout of legacy queries when migrating databases between different environments like PostgreSQL and MySQL.
Quick Testing Templates
Test the SQL syntax formatter instantly. Click the templates below to load sample queries directly into the IDE.
Engineering FAQ
Paste the query, pick the database dialect or leave it on auto-detect, and press Format (Ctrl/Cmd + Enter). Choose the indentation, whether keywords are UPPER or lower case, and how AND/OR and long lists wrap; save the choices as a named profile to reuse or share with your team. Use Minify to put a query back on one line, and Selection to format only the part you highlighted.
Database queries inherently contain sensitive information, including proprietary schema designs, table structures, and business logic. Processing queries purely in your local browser prevents this critical data from being intercepted or logged on external servers.
The formatter safely processes standard SQL comments. However, when using the "Minify" function, inline comments (--) may be stripped or reformatted to prevent them from accidentally commenting out the rest of the single-line string.
No. Profiles are kept in this browser's local storage. Export writes them to a JSON file you can commit to a repository or send to a colleague, and Import reads that file back. In a private window the browser may discard them when you close it.
It never connects to a database or runs anything. The Every dialect panel parses the query with node-sql-parser's grammar for 14 databases and shows the line and column where each one stops. That catches syntax a database does not have, such as TOP or square brackets outside SQL Server. It cannot catch a missing table or a wrong column type, and a parser can stop at a valid statement it does not cover, so a red row means "look here", not "this is wrong". Oracle PL/SQL and Spark have no parser here.
Why query formatting is a review problem, not a cosmetic one
A query written as one 600-character line is not just unpleasant to read — it is effectively unreviewable. Every change to it produces a diff showing one line removed and one line added, so a reviewer cannot see whether you altered a join condition or only a column alias. Consistent formatting turns SQL into something version control can describe meaningfully.
That is the real argument for a formatter: not beauty, but making the WHERE clause you changed visible as a changed line rather than buried inside an unchanged wall of text.
Keyword casing
Upper-casing reserved words (SELECT, JOIN, WHERE) separates language from identifiers at a glance. SQL keywords are case-insensitive, so this is purely for readability — but it is the convention nearly every style guide lands on.
Clause alignment
Putting each major clause on its own line, with joins and conditions indented beneath, makes the query's shape match its logic. Nested subqueries become visibly nested instead of implied by parentheses alone.
One column per line
For long select lists this is the difference between a reviewable diff and an unreviewable one. Adding a column becomes a single added line, which is exactly what you want a code review to show.
Where dialects genuinely diverge
"Standard SQL" is closer to an aspiration than a description. Formatting has to know which dialect it is looking at, because the same characters mean different things:
- Identifier quoting. ANSI and PostgreSQL use double quotes (
"order"), MySQL uses backticks (`order`), SQL Server uses brackets ([order]). In MySQL, double-quoted text is a string literal unlessANSI_QUOTESis enabled — so the same query can parse differently depending on a server setting. - String concatenation.
||in PostgreSQL and Oracle,CONCAT()in MySQL,+in SQL Server. - Row limiting.
LIMIT nin PostgreSQL and MySQL,TOP nin SQL Server,FETCH FIRST n ROWS ONLYin Db2 and standard SQL. - Comment syntax.
--and/* */are near-universal, but MySQL requires whitespace after--, so--commentis a subtraction of a negative rather than a comment. - Parameter placeholders.
$1,?and@nameare all conventions you will meet, and a formatter must leave them intact.
Formatting is not sanitising
Worth stating plainly: making a query readable does nothing about SQL injection. If any part of a query is assembled from user input by string concatenation, it is injectable whether it is beautifully indented or not. The fix is parameterised queries — placeholders bound by the driver, so user input is never parsed as SQL. A formatter is a readability tool, and reading a query is often how you notice a concatenation that should have been a parameter.
Equally, a formatter does not change how a query performs. It rewrites whitespace, never semantics: no clause is reordered, no join is rewritten, no index is chosen differently. For performance work you want EXPLAIN, not a formatter — though a readable plan is considerably easier to reason about alongside a readable query.
Your queries do not leave the page
Production SQL tends to contain table names, column names, business logic and sometimes literal customer data in a WHERE clause. All of that is competitively and legally sensitive, and none of it should be pasted into a service you cannot inspect. This formatter is client-side JavaScript: the parsing and re-rendering happen in the page you have open, nothing is transmitted, and you can verify that in your browser's Network tab or simply by working offline.
Deployment Changelog
- v1.5.0 Named style profiles with JSON import and export, and six more options (AND/OR placement, data type and identifier case, line width, dense operators, semicolon line). Six checks with one-click fixes and Fix all, format selection only, many files to a zip with a per-file report, syntax errors per database from node-sql-parser with line and column, and autocomplete from pasted CREATE TABLE statements.
- v1.4.0 Expanded enterprise documentation, detailing tabular formatting and the 16+ supported dialect configurations.
- v1.3.1 Replaced the deprecated
commaPositionformatter config with the supportedindentStyleoption (Standard / Tabular Left / Tabular Right) to fix a formatting error. - v1.3.0 Added line numbers, configurable format options (indent, keyword case, comma position, function case), 11 additional dialects, single-line minify mode, .sql download, keyboard shortcuts, and persistent session state.
- v1.2.2 Truncated the AST stack trace dump output to prevent parser failures from breaking the UI wrapper.
- v1.2.1 Fixed error testing template to reliably trigger syntax parsing alerts across all dialects.
- v1.2.0 Added interactive Quick Testing Templates and dynamic dialect switching for optimized testing.
- v1.1.0 Integrated client-side syntax highlighting for SQL keywords, strings, and numeric values.
- v1.0.0 Initial release of the Universal SQL Formatter engine utilizing secure, local processing.