# Generate and Optimize SQL Queries from Natural Language

Writing complex SQL queries requires deep database knowledge and is time-consuming for non-experts. This skill translates natural language descriptions into optimized SQL statements with execution plans and performance recommendations.

## Install

```bash
npx skillstore add hermes-sedimentary/zhangchenlai-dev-sql-query-builder
```

## Metadata

- - Slug: zhangchenlai-dev-sql-query-builder
- - Version: 1.0.0
- - Author: Hermes-Sedimentary
- - GitHub username: zhangchenlai-dev
- - License: MIT
- - Repository: https://github.com/zhangchenlai-dev/hermes-skill-store/tree/master/sql-query-builder
- - Ref: master
- - Supported tools: Claude, Codex, Claude Code
- - Risk level: safe
- - Quality score: 80
- - Quality tier: silver
- - Public page: https://skillstore.pages.dev/skills/zhangchenlai-dev-sql-query-builder
- - Manifest: https://skillstore.pages.dev/api/skills/zhangchenlai-dev-sql-query-builder/manifest

## Capabilities

- Convert natural language descriptions into valid SQL queries
- Analyze query execution plans and identify bottlenecks
- Suggest index optimizations and query rewrites
- Support multiple SQL dialects and database systems
- Explain complex SQL logic in plain language

## Use Cases

- Rapid Query Prototyping: Data analysts use natural language to quickly generate SQL queries for ad-hoc reporting and exploration.
- Query Performance Tuning: Developers receive execution plan analysis and optimization suggestions to fix slow-running database queries.
- SQL Learning Assistant: Students and junior engineers learn SQL by seeing how natural language maps to structured query language.

## Prompt Templates

### Basic Query Generation

```
Write a SQL query to find all customers who signed up in the last 30 days.
```

### Join and Filter

```
Generate a query that joins the orders and customers tables to find total spending per customer in 2024.
```

### Execution Plan Analysis

```
Analyze why this query is slow and suggest optimizations: SELECT * FROM large_table WHERE status = 'pending' ORDER BY created_at DESC
```

### Complex Aggregation

```
Create a query to calculate monthly revenue by product category with running totals and percentage growth.
```

## Limitations

- Cannot execute queries directly against live databases
- Requires human review for production-critical queries
- Optimization suggestions depend on schema information provided by the user
- May not support proprietary or niche database extensions

## Best Practices

- Always review generated SQL in a non-production environment before deployment
- Provide clear schema details and table relationships for more accurate queries
- Test optimization suggestions against representative data volumes

## Anti Patterns

- Do not run generated queries directly on production databases without review
- Avoid vague natural language prompts that lack table or column context
- Do not ignore database-specific syntax differences when copying queries across platforms

## Security Audit

- - Safe to publish: true
- - Audited at: 2026-05-21T18:11:01.114\+00:00
- - Summary: Two high-severity static findings were evaluated and dismissed as false positives. The 'weak cryptographic algorithm' alert at line 4 triggered on Chinese text and UTF-8 symbols in the description field, which contains no cryptography whatsoever. The 'high file entropy' alert is caused by Chinese characters encoded in UTF-8, not binary or encrypted content. The skill consists solely of plain markdown documentation with no executable code, network requests, file system operations, environment variable access, or external command invocations. No malicious intent or security issues were identified.

## Stats

- - Views: 0
- - Downloads: 0
- - Favorites: 0
- - Popularity score: 0
