Format SQL queries with proper indentation and line breaks. Transform compressed SQL into readable, well-structured queries with keyword highlighting and alignment.
SQL formatting transforms compressed or poorly written SQL queries into well-structured, readable code. Proper formatting places major keywords (SELECT, FROM, WHERE, JOIN) on new lines with consistent indentation, making complex queries easier to understand, debug, and maintain. This is especially valuable for database administrators and developers working with large, complex queries.
Formatted SQL = Major keywords on new lines + Consistent indentation + Aligned clauses + Proper spacingSQL formatting works by identifying major keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, etc.) and placing them on new lines with appropriate indentation. Sub-clauses are further indented, and commas in SELECT lists are aligned for readability. Operators get consistent spacing.
| Input | Output |
|---|---|
| SELECT id,name,email FROM users WHERE active=1 ORDER BY name | SELECT id, name, email FROM users WHERE active = 1 ORDER BY name |
| SELECT u.name,o.total FROM users u JOIN orders o ON u.id=o.user_id WHERE o.total>100 | SELECT u.name, o.total FROM users u JOIN orders o ON u.id = o.user_id WHERE o.total > 100 |
| INSERT INTO users(name,email) VALUES('John','john@example.com') | INSERT INTO users (name, email) VALUES ('John', 'john@example.com') |