---
name: sql-database-query-generator
description: "One correct SQL statement from a table, columns, conditions, and row limit, in your database's syntax, ready to paste into a console for a quick check or prototype. Use when a quick single-table SELECT, INSERT, UPDATE, or DELETE is needed in the right dialect syntax to paste into a database console. Do not use for multi-table analytics, query tuning, or statements that must be designed against a full schema. Related topics: coding, sql."
---

# SQL Database Query Generator

One correct SQL statement from a table, columns, conditions, and row limit, in your database's syntax, ready to paste into a console for a quick check or prototype.

## When to use

Use this skill when a quick single-table SELECT, INSERT, UPDATE, or DELETE is needed in the right dialect syntax to paste into a database console. Do not use it for multi-table analytics, query tuning, or statements that must be designed against a full schema.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Write one statement in the chosen database's syntax for identifier quoting, string quoting, and row limiting.
3. For SELECT, list the columns explicitly and add ORDER BY when given so the limit is deterministic.
4. For INSERT, pair every column with a placeholder value of the right type.
5. For UPDATE and DELETE, attach the conditions as WHERE; when none are given, add an incomplete WHERE and a note instead of an unconditioned write.
6. Confirm the result is a single statement ending in a semicolon with one clause per line.

## Inputs

- **Database** (choose one: MySQL, PostgreSQL, SQLite, SQL Server, Oracle)
- **Operation** (choose one: SELECT, INSERT, UPDATE, DELETE)
- **Table name** (free text, e.g. "users")
- **Columns** (longer free text)
- **Conditions** (longer free text)
- **Row limit** (number from 1 to 1000)
- **Order by (optional)** (free text, e.g. "created_at descending")

## Output

The single SQL statement as plain text, one clause per line, ending with a semicolon, plus a one-line safety note only when a write has no condition.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Quick SQL Statement

Generate a single SQL statement.

- Database: {{Database}}
- Operation: {{Operation}}
- Table name: {{Table name}}
- Columns: {{Columns}}
- Conditions: {{Conditions}}
- Row limit: {{Row limit}}
- Order by (optional): {{Order by (optional)}}

Write exactly one statement that the chosen database accepts as written: its identifier quoting, its string quoting, and its own way to limit rows (LIMIT for MySQL, PostgreSQL, and SQLite; TOP for SQL Server; FETCH FIRST n ROWS ONLY for Oracle). For SELECT, list the columns explicitly rather than using a star, and add the ORDER BY when given so the limit is deterministic. For INSERT, pair the columns with placeholder values of the right type. For UPDATE and DELETE, include the conditions as the WHERE clause; when no condition is given, say that the statement would affect every row and add a WHERE clause the user must complete instead of running it bare. Keep the statement on readable lines with one clause per line.

Return the complete statement as plain text ending with a semicolon, and nothing else unless a safety note is needed for an unconditioned write.

## Pitfalls

- Using LIMIT for SQL Server, which rejects it; the syntax is TOP or OFFSET FETCH.
- Generating a DELETE without a WHERE clause because the conditions field was empty.
- Applying a row limit without an ORDER BY, which returns a different set of rows each time.
