The SQL Formatter beautifies SQL queries with proper indentation, keyword capitalization, and line breaks. Supports multiple database dialects including MySQL, PostgreSQL, SQLite, SQL Server, Oracle, and more.
select p.product_name,c.category_name,sum(oi.quantity) as total_sold,sum(oi.quantity*oi.unit_price) as revenue from order_items oi join products p on oi.product_id=p.id join categories c on p.category_id=c.id where oi.order_date between '2024-01-01' and '2024-12-31' group by p.product_name,c.category_name having sum(oi.quantity*oi.unit_price)>1000 order by revenue desc;
with monthly_sales as(select date_trunc('month',order_date) as month,sum(total) as sales from orders group by month),top_months as(select month,sales,rank() over(order by sales desc) as rank from monthly_sales)select * from top_months where rank<=3;
CREATE TABLE users(id SERIAL PRIMARY KEY,username VARCHAR(50) UNIQUE NOT NULL,email VARCHAR(255) UNIQUE NOT NULL,password_hash VARCHAR(255) NOT NULL,created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
select employee_id,department_id,salary,avg(salary) over(partition by department_id) as dept_avg,rank() over(partition by department_id order by salary desc) as dept_rank from employees;
case 'sql-formatter': { const language = action === 'default' ? 'sql' : action; const { format: formatSql } = await import('sql-formatter'); return { output: formatSql(input, { language: language as any }) };}
Uses the sql-formatter library with dialect-specific parsing for accurate formatting across different SQL variants.
For best results, select the specific dialect that matches your database. Dialect-specific formatting handles vendor-specific syntax and keywords correctly.
The formatter preserves SQL logic but may change query structure. Always test formatted queries in a development environment before using in production.