SQL Query Generator

Describe a table once and generate CREATE TABLE, INSERT, SELECT, UPDATE, and DELETE statements for MySQL, PostgreSQL, SQLite, or SQL Server, with identifiers and values quoted correctly.

Updated
Only writes SQL text. Nothing is sent to a database.
Columns
Statement
Set
Where
Generated SQL

How to use the SQL Query Generator

  1. Pick the Database and enter the Table name. Add Columns with a name, type, and the primary key, not null, and default options.
  2. Choose the Statement. For INSERT, paste rows as CSV. For SELECT, UPDATE, and DELETE, add Where conditions, and for UPDATE the new values.
  3. Copy the SQL from Generated SQL.

How it works

  • Identifiers are quoted the way each database expects: `name` in MySQL, "name" in PostgreSQL and SQLite, and [name] in SQL Server.
  • String values go in single quotes, and a single quote inside a value is doubled: O'Brien becomes 'O''Brien'. Numbers are written as they are, and an empty cell or NULL becomes NULL.
  • Column types are translated for each database. An auto-increment integer key becomes INT NOT NULL AUTO_INCREMENT in MySQL, INTEGER GENERATED ALWAYS AS IDENTITY in PostgreSQL, INTEGER PRIMARY KEY AUTOINCREMENT in SQLite, and INT IDENTITY(1,1) in SQL Server.
  • INSERT writes all CSV rows as one multi-row statement.
  • UPDATE and DELETE without a WHERE condition get a warning comment, because they change every row.

Examples

Table users with id (auto-increment key), email (text, not null), and active (boolean, default true), for PostgreSQL:

CREATE TABLE "users" (
  "id" INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  "email" VARCHAR(255) NOT NULL,
  "active" BOOLEAN DEFAULT TRUE
);

UPDATE setting active to false where email = [email protected]:

UPDATE "users"
SET "active" = FALSE
WHERE "email" = '[email protected]';

Limitations

  • The generator covers one table at a time. Joins, foreign keys, indexes, and subqueries are not built.
  • The SQL isn't run or checked against a real database.
  • For queries in application code, use parameterized statements instead of pasting values into SQL.

Frequently asked questions

Is the generated SQL safe from SQL injection?

Values are escaped for a one-off query you run yourself. In application code, always use prepared statements with parameters rather than building SQL strings.

Why do MySQL and PostgreSQL quote names differently?

MySQL uses backticks by default, while PostgreSQL, SQLite, and standard SQL use double quotes. SQL Server uses square brackets. Quoting lets you use names that clash with keywords, such as order.

Can I insert many rows at once?

Yes. Paste the rows as CSV, one per line, and the tool writes one INSERT with several value lists. All four databases accept this.

Is anything sent to a database?

No. The tool only writes text in your browser.

Often used together with the SQL Query Generator.