dataintermediate

SQL Query Builder

Translates natural language questions into optimized SQL queries with explanations.

Prompt

Convert this natural language question into an optimized SQL query:

**Question**: {{question}}
**Database**: {{database}} (PostgreSQL/MySQL/SQLite/BigQuery)
**Schema**:
{{schema}}

Provide:
1. **SQL query**: formatted, with comments explaining each section
2. **Execution plan notes**: expected index usage, potential full table scans
3. **Performance tips**: indexes to add, partitioning suggestions if dealing with large tables
4. **Edge cases**: what happens with NULL values, empty results, or unexpected data
5. **Alternative approaches**: if there are multiple valid ways to write this query, show the tradeoffs

If the question is ambiguous, state your assumptions clearly.

Variables

{{question}}{{database}}{{schema}}

Example Output

```sql
-- Find the top 10 customers by total order value in the last 90 days
SELECT c.id, c.name, SUM(o.total) as total_spent
FROM customers c...

Use Cases

  • Ad-hoc data analysis
  • Building reporting queries
  • Learning SQL patterns

Compatible Models

claude-sonnet-4-20250514gpt-4ogemini-2.5-pro

Tags

sqldatabasequery-optimization

Details

Author
PromptIndex
Updated
2026-04-01
Difficulty
intermediate

Related Prompts