FormatterHQ

SQL Tools

Format, minify and escape SQL queries, and convert table data between SQL INSERT statements and CSV, JSON, XML, YAML or HTML.

CSV to SQL Converter Convert CSV to SQL online for free. CREATE TABLE and INSERT statements with escaped values. JSON to SQL Converter Convert JSON to SQL online for free. CREATE TABLE and INSERT statements with escaped values. SQL Escape SQL escape online: convert special characters into escape sequences so text is safe inside SQL. SQL Formatter Format SQL queries online for MySQL, PostgreSQL, SQL Server, Oracle, SQLite, BigQuery and more. SQL Minifier Minify SQL queries into a single compact line while keeping strings intact. SQL Syntax Validator Check SQL syntax for MySQL, PostgreSQL, SQLite, SQL Server, BigQuery and more; pinpoint the line and column of errors. SQL to CSV Converter Convert SQL to CSV online for free. Nested data is flattened into columns. SQL to HTML Table Converter Convert SQL to HTML online for free. Get clean table markup with a live preview. SQL to JSON Converter Convert SQL to JSON online for free. Get formatted JSON with types detected automatically. SQL to Laravel Migration Convert MySQL or PostgreSQL CREATE TABLE statements into Laravel Schema::create migrations with foreign keys and indexes. SQL to MongoDB Query Converter Translate SQL SELECT, INSERT, UPDATE and DELETE statements into MongoDB find(), aggregate() and update queries. SQL to XML Converter Convert SQL to XML online for free. Attributes, arrays and root element are configurable. SQL to YAML Converter Convert SQL to YAML online for free. Clean, readable YAML with configurable indentation. SQL Unescape SQL unescape online: turn escaped sequences back into readable plain text instantly.

SQL tools for readable queries and portable data

SQL queries tend to arrive in awkward shapes: a single 2,000-character line from an ORM log, a query pasted from a ticket with inconsistent capitalization, or a dump full of INSERT statements when you only wanted a spreadsheet. These SQL tools make queries readable and move data in and out of SQL.

Which SQL tool do you need?

  • Read a complex query – the SQL formatter puts each clause on its own line, indents subqueries and joins and normalizes keyword case.
  • Compact a query – the SQL minifier removes comments and whitespace, handy for embedding a query in code or a URL.
  • Escape values – SQL escape doubles single quotes in string literals, and SQL unescape reverses it.
  • Import data – CSV to SQL and JSON to SQL create CREATE TABLE and INSERT statements from files.
  • Export data – SQL to CSV, SQL to JSON and SQL to HTML turn INSERT statements back into tables, as do the SQL to XML and SQL to YAML converters.

Common workflows

Reviewing a slow query: copy it from your database log or ORM debug output, format it, and read the joins and WHERE conditions clause by clause. Formatted SQL makes missing join conditions and accidental cross joins obvious.

Seeding a test database: generate fake rows with the random CSV generator, convert them with CSV to SQL, and run the script against your development database.

Sharing data from a dump: extract the INSERT statements for one table and convert them to CSV for colleagues who work in spreadsheets.

Why format SQL at all?

SQL is often written once and read many times: in code review, during incident analysis and when onboarding new team members. A consistent layout, with keywords in one case and one clause per line, makes those readings faster and reduces mistakes.

Reading ORM output

ORMs such as Eloquent, Hibernate and Entity Framework log generated SQL as a single line with placeholders. Formatting that output is often the fastest way to understand what the framework is actually asking the database, for example spotting an N+1 pattern where the same query appears hundreds of times with different IDs.

SQL tips

  • Escaping by hand is fine for one-off scripts, but application code should always use parameterized queries (prepared statements) to prevent SQL injection.
  • Dialects differ: MySQL uses backticks for identifiers, PostgreSQL and standard SQL use double quotes, SQL Server uses square brackets.
  • Formatting does not change what a query does, so it is safe to format production queries for reading.
  • Queries and data are processed in your browser and never sent to a database or server.

Frequently asked questions

Does formatting SQL change the query result?
No. The formatter only changes whitespace, line breaks and keyword case, which do not affect how the database executes the query.
Which SQL dialects are supported?
Standard SQL and common dialects such as MySQL, PostgreSQL, SQL Server and SQLite are handled by the formatter. Dialect-specific syntax is kept as written.
How do I escape a single quote in SQL?
Double it: the name O'Brien is written as 'O''Brien' inside a SQL string literal. In application code, use parameterized queries instead of manual escaping.
Can I convert a CSV file into INSERT statements?
Yes. CSV to SQL reads the header row as column names and generates a CREATE TABLE statement plus one INSERT per row.