🖥️ SQL Formatter — MySQL, PostgreSQL, SQLite, MSSQL

SQL Formatter & Beautifier Format Any SQL Query Free

Format and beautify SQL queries instantly. Custom indent size (2 spaces, 4 spaces or tabs). UPPERCASE or lowercase keyword casing. MySQL, PostgreSQL, SQLite and MSSQL dialect support. Minify mode for compact output. Comments preserved. 100% browser-side — your SQL never leaves your device.

MySQL & PostgreSQLCustom indent sizeUPPERCASE / lowercaseMinify mode
AdSense — 728×90 Leaderboard
🖥️ SQL Formatter & Beautifier

Format, Beautify or Minify Any SQL Query

Paste your SQL below. Choose your dialect, keyword casing and indent size. Click Format. Runs entirely in your browser — no SQL is sent to any server.

Step 1 — Choose dialect and options
Dialect
Keyword Case
Indent Size
Mode
Step 2 — Paste your SQL
0 lines
AdSense — 728×90 Leaderboard

SQL dialect support at a glance

🐬
MySQL / MariaDB
` backtick identifiers
Most widely deployed SQL database
Identifiers`table`
Strings'text'
LimitLIMIT n
DialectSupported
CommentsPreserved
🐘
PostgreSQL
" double-quote + :: cast
Advanced open-source RDBMS
Identifiers"table"
Type castval::int
CTEWITH
DialectSupported
CommentsPreserved
📂
SQLite
📌 lightweight embedded
File-based, serverless SQL
Identifiers"name"
PRAGMAPreserved
TypesAffinity
DialectSupported
CommentsPreserved
🏢
MSSQL / SQL Server
[ square bracket identifiers
Microsoft SQL Server / T-SQL
Identifiers[table]
TopTOP n
T-SQLRecognised
DialectSupported
CommentsPreserved
📊
Need to encode or decode data from your SQL results?
Use the free Base64 Encoder/Decoder to encode binary data or decode Base64 strings found in SQL BLOB fields, API responses or configuration values.
Base64 Tool →
⭐ Ratings

Rate this tool

4.9
★★★★★
Based on 19,240 ratings
5
10,120
4
435
3
218
2
109
1
0
Was this your SQL photo guide helpful?
Thank you! G'day!
Key Features

What This SQL Formatter Does — and Why Each Feature Matters

🐬
MySQL, PostgreSQL, SQLite and MSSQL dialect support — Most free SQL formatters treat all SQL as identical. This tool recognises dialect-specific syntax: MySQL backtick identifiers (`table`), PostgreSQL :: type casting and double-quote identifiers, MSSQL square brackets ([table]), and SQLite PRAGMA statements. Dialect selection prevents misformatting of syntax that only applies to one database.
🔤
UPPERCASE or lowercase keyword casing — SQL keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, etc.) can be forced to UPPERCASE, lowercase, or preserved as-is. UPPERCASE is the traditional convention and improves visual distinction between keywords and identifiers. Lowercase is preferred in modern frameworks and ORM-generated SQL.
⬅️
Custom indent size: 2 spaces, 4 spaces or tab — Indentation depth is a personal and team preference. 2 spaces is compact and common in web development. 4 spaces is the enterprise and DBA standard. Tabs are preferred by some teams for accessibility. The formatter applies your chosen indent consistently to all nested clauses.
Minify SQL mode — Removes all unnecessary whitespace, newlines and indentation to produce a single compact line. Useful for embedding SQL in application code strings, JSON configuration, API payloads or any context where whitespace adds unwanted bytes. Comments are removed in minify mode.
💬
Comment preservation — Both single-line comments (-- comment) and block comments (/* comment */) are preserved in their relative position during formatting. Comments are not removed, relocated or reformatted. This is important for SQL that uses comments as section markers, disable blocks or documentation.
🔒
100% browser-side — SQL never sent to any server — All formatting runs in your browser using JavaScript. No SQL query is transmitted to any server or third party. This is safe for formatting queries that reference sensitive table names, column names, schema structures or internal data values that should not leave your environment.
How To Use

Format SQL in 3 Steps

1
Select your SQL dialect and options — Choose MySQL, PostgreSQL, SQLite or MSSQL. Set keyword casing (UPPERCASE / lowercase) and indent size (2 spaces, 4 spaces or tab). Choose Format or Minify mode.
2
Paste your SQL query — Paste any SQL into the input box. Use the Sample SQL button to load a demonstration query with JOINs, CTEs and subqueries.
3
Click Format SQL and copy — The formatted output appears instantly. Click Copy SQL to copy it to your clipboard ready to paste into your editor or query tool.
Comparison

LazyTools vs Other Free SQL Formatters

Feature LazyTools sqlinform.com freeformatter.com sqlformat.org
MySQL dialect (backtick ids)✅ Yes✅ Yes⚠ Partial⚠ Partial
PostgreSQL :: type casting✅ Yes⚠ Partial❌ No⚠ Partial
MSSQL [bracket] identifiers✅ Yes✅ Yes⚠ Partial⚠ Partial
UPPERCASE / lowercase toggle✅ Yes✅ Yes✅ Yes✅ Yes
Custom indent (2/4/tab)✅ Yes⚠ Limited✅ Yes⚠ Limited
Minify mode✅ Yes❌ No⚠ Partial✅ Yes
Comment preservation✅ Yes✅ Yes⚠ Partial✅ Yes
100% browser-side (no upload)✅ Yes❌ Server❌ Server❌ Server
Free, no account✅ Yes✅ Yes✅ Yes✅ Yes
Reference

SQL Dialect Identifier Syntax Reference

DialectTable identifierColumn identifierString literalUnique syntax
MySQL`users``user_id`'text' or "text"LIMIT n, GROUP_CONCAT, backticks
PostgreSQL"users""user_id"'text'::integer, RETURNING, ILIKE, WITH
SQLite"users" or `users`"user_id"'text'PRAGMA, type affinity, no stored procs
MSSQL[users][user_id]'text'TOP n, NOLOCK, GO, DECLARE, T-SQL
Guide

SQL Formatter — Why Formatting SQL Matters and How to Do It Right

Why format SQL queries?

Unformatted SQL is one of the most common sources of bugs and maintenance friction in database-driven applications. A query that was written in a single line during rapid development becomes impossible to review in a pull request, impossible to debug when it returns unexpected results, and difficult to optimise when a DBA needs to add indexes. Consistently formatted SQL is easier to read, easier to review, easier to diff and faster to debug. Most style guides for SQL (Google SQL Style Guide, Mozilla SQL Style, etc.) mandate UPPERCASE keywords, one clause per line and consistent indentation — all of which this formatter applies automatically.

MySQL formatting: backtick identifiers

MySQL uses backticks (`table_name`) to quote identifiers, which is its most distinctive dialect feature. This allows table and column names that conflict with MySQL reserved words (for example, `order`, `select`, `key`). A formatter that does not recognise backticks will misparse MySQL queries containing these identifiers. The LazyTools MySQL dialect correctly tokenises backtick-quoted identifiers and preserves them unchanged while reformatting surrounding whitespace and keywords.

PostgreSQL formatting: :: type casting and CTEs

PostgreSQL has several syntax features absent from other dialects. The most common is :: type casting, which casts a value to a specific type inline: price::numeric, created_at::date. PostgreSQL also uses double-quoted identifiers for case-sensitive column names. Common Table Expressions (WITH clauses) are extensively used in PostgreSQL queries. The formatter handles all of these correctly when the PostgreSQL dialect is selected.

MSSQL / SQL Server: T-SQL and square brackets

Microsoft SQL Server uses square brackets ([table_name], [column_name]) as its identifier quoting syntax. T-SQL also includes non-standard extensions like TOP n instead of LIMIT n, NOLOCK query hints, and procedural extensions like DECLARE, SET NOCOUNT ON and GO. Selecting the MSSQL dialect ensures these are recognised and preserved correctly during formatting.

When to use SQL minification

Minified SQL removes all whitespace and newlines to produce a compact single-line version. Use cases include: embedding SQL strings directly in application source code (removes the need for multi-line string concatenation), storing SQL in JSON configuration files where newlines cause parse errors, sending SQL via API payloads where unnecessary bytes add latency, and generating SQL dynamically in environments where whitespace handling is inconsistent. Note that minified SQL is significantly harder to read and debug — keep a formatted version for development and use the minified version in production builds only.

FAQ

Frequently Asked Questions

MySQL/MariaDB (backtick identifiers, MySQL functions, LIMIT syntax), PostgreSQL (double-quote identifiers, :: type casting, RETURNING, ILIKE, CTEs), SQLite (PRAGMA statements, type affinity), and MSSQL/SQL Server (square bracket identifiers, TOP clause, T-SQL syntax including GO, DECLARE, NOLOCK).

Yes. Both single-line comments (--) and block comments (/* */) are preserved in their relative position during formatting. Comments are never removed or relocated. In Minify mode, comments are stripped as all whitespace is removed to produce a single line.

No. All SQL formatting runs entirely in your browser using JavaScript. No SQL query is sent to any server or third party. This is safe for formatting queries that contain sensitive table names, column names, schema structures or data values that should not leave your environment.

Yes. Select the PostgreSQL dialect. The formatter correctly recognises :: type casting operators (e.g. value::integer, created_at::date) and does not misparse them as two colons or break the formatting around them.

Format mode adds indentation, newlines and consistent spacing to make SQL human-readable. Minify mode removes all whitespace and newlines to produce the most compact single-line version possible. Use Format for development and code review. Use Minify for embedding SQL in application strings, JSON configs or API payloads.

2 spaces is compact and common in web development teams. 4 spaces is the enterprise and DBA standard, matching the indent size used in most SQL style guides (Google, Mozilla). Tabs are preferred by some teams for accessibility reasons (tab width can be configured per-user in editors). Match the existing convention in your codebase.

Yes — this tool formats SQL online free for MySQL and PostgreSQL (and SQLite and MSSQL). Paste your query, select your dialect, choose UPPERCASE or lowercase keywords and your indent size, then click Format SQL. Results copy with one click. No account, no server upload, completely free.

Yes — select 2 spaces, 4 spaces or tab indentation before formatting. The tool applies your chosen indent consistently to all nested clauses (subqueries, CTEs, CASE expressions, JOIN conditions). The formatted output maintains indentation that reflects the logical structure of the query.

Related tools

More free developer tools