SQL Formatter & Beautifier - Format SQL Queries Online
Format, beautify, and minify SQL queries with syntax highlighting. Supports MySQL, PostgreSQL, SQLite, T-SQL, and PL/SQL dialects.
Frequently Asked Questions
What is a SQL formatter?
A SQL formatter (also called SQL beautifier or SQL pretty printer) is a tool that takes SQL queries and reformats them with proper indentation, line breaks, and consistent styling to improve readability. It transforms compressed or poorly formatted SQL into clean, structured code that is easier to read, review, and debug. SQL formatters are essential for working with auto-generated queries from ORMs, minified production SQL, or legacy code with inconsistent formatting.
How do I use this SQL formatter?
1. Paste or type your SQL query into the input area, or upload a .sql file. 2. Select your SQL dialect (MySQL, PostgreSQL, SQLite, etc.) for accurate formatting. 3. Choose the Format tab to beautify or the Minify tab to compress. 4. Adjust options like indentation (2 spaces, 4 spaces, tabs) and keyword case (UPPER, lower, preserve). 5. The output updates automatically in real-time. 6. Click Copy to copy the result to your clipboard, or Download to save as a .sql file. 7. Share your settings via the URL — all options are preserved in the URL parameters.
Is my SQL data safe? Does it get sent to a server?
Your SQL queries are 100% safe and never leave your browser. This tool processes all formatting and minification entirely on your device using the sql-formatter JavaScript library running in your browser. No SQL data is ever transmitted to any server, stored in any database, or logged anywhere. This is especially important for developers working with production queries that may contain sensitive table names, column names, or data patterns. You can verify this by disconnecting from the internet — the tool works fully offline.
What SQL dialects are supported?
This formatter supports 10 SQL dialects: Standard SQL, MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), MariaDB, Oracle PL/SQL, BigQuery, Snowflake, and Amazon Redshift. Each dialect has its own set of reserved keywords, functions, and syntax rules. Selecting the correct dialect ensures that database-specific keywords and functions are properly recognized and formatted. If you are unsure which dialect to use, Standard SQL provides good general-purpose formatting.
What is the difference between formatting and minifying SQL?
Formatting (beautifying) adds proper indentation, line breaks, and consistent spacing to make SQL queries human-readable. It is ideal for code reviews, documentation, and debugging. Minifying removes all unnecessary whitespace, newlines, and comments to produce the most compact SQL possible. Minification is useful for reducing the size of SQL in configuration files, logging, or transmission. For example, a 500-character formatted query might minify to 200 characters, a 60% reduction.
Can I customize the keyword case (UPPER/lower)?
Yes. You can independently control the case for three categories: SQL keywords (SELECT, FROM, WHERE, JOIN, etc.), functions (COUNT, SUM, AVG, COALESCE, etc.), and data types (VARCHAR, INTEGER, BOOLEAN, etc.). Each can be set to UPPER CASE, lower case, or Preserve (keep original). This is useful for teams that follow specific SQL coding standards or style guides.
Code Examples
import { format } from 'sql-formatter';
// Format SQL
const ugly = "SELECT u.id, u.name, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id WHERE o.total > 100 AND u.active = 1 ORDER BY o.total DESC LIMIT 10;";
const formatted = format(ugly, {
language: 'mysql',
tabWidth: 2,
keywordCase: 'upper',
});
console.log(formatted);
// SELECT
// u.id,
// u.name,
// o.total
// FROM
// users u
// INNER JOIN orders o ON u.id = o.user_id
// WHERE
// o.total > 100
// AND u.active = 1
// ORDER BY
// o.total DESC
// LIMIT
// 10;
// Minify SQL
function minifySQL(sql) {
return sql
.replace(/--.*$/gm, '')
.replace(/\/\*[\s\S]*?\*\//g, '')
.replace(/\s+/g, ' ')
.trim();
}
console.log(minifySQL(formatted));
Does the formatter handle comments in SQL?
Yes. In Format mode, both single-line comments (-- comment) and multi-line comments (/* comment */) are preserved and properly indented within the formatted output. In Minify mode, comments are stripped to achieve maximum compression. The formatter correctly handles comments that appear between SQL clauses, after statements, and inline within expressions.