SQL Formatter
Formats SQL queries for MySQL, PostgreSQL, SQLite, SQL Server, and more.
This SQL minifier strips comments and squeezes a query onto one line, without touching anything inside strings, quoted names, or PostgreSQL dollar quotes.
Paste a query on the left, upload a .sql file, or try the sample to see how much you can save.
0%
.sql file, or load one from a URL.minified.sql.The minifier reads the SQL token by token instead of using search and replace, so a -- inside 'a -- b' stays part of the string. These are copied exactly as written:
'' as an escaped quote, plus \' in MySQL;$fn$ ... $fn$, common in function definitions;/*! ... */ and optimizer hints /*+ ... */, because the database reads them.Everything else is joined with single spaces. Spaces before a comma, semicolon, or closing bracket, and after an opening bracket, are dropped too.
This query:
SELECT id,
name -- the name
FROM users
WHERE id = 1;becomes SELECT id, name FROM users WHERE id = 1;
In MySQL, SELECT 5--3 stays as it is, because MySQL needs a space after -- for a comment and reads this as 5 minus minus 3. Under Standard SQL the same text is SELECT 5 followed by a comment.
With Keep comments ticked, -- note turns into /* note */, which survives on one line.
Not noticeably for the database, which parses whitespace quickly. It helps when SQL is embedded in code, logs, or URLs, where one short line is easier to handle.
Bodies in dollar quotes and strings are left alone. Check MySQL procedures that use DELIMITER, since the delimiter line needs its own line to work in the mysql client.
Run the result through the SQL Formatter to get indentation back. Removed comments cannot be restored.
Often used together with SQL Minifier.
Formats SQL queries for MySQL, PostgreSQL, SQLite, SQL Server, and more.
Syntax check of SQL statements per dialect, with the error position and expected tokens.
Generates CREATE, INSERT, SELECT, UPDATE, and DELETE statements for four databases.