This tool generates SQL syntax by inspecting database schemas to assist with data extraction, reporting, and troubleshooting.

Install

mkdir -p .claude/skills/query-writing && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1056" && unzip -o skill.zip -d .claude/skills/query-writing && rm skill.zip

Installs to .claude/skills/query-writing

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Writes and executes SQL queries from simple SELECTs to complex multi-table JOINs, aggregations, and subqueries. Use when the user asks to query a database, write SQL, run a SELECT statement, retrieve data, filter records, or generate reports from database tables.
263 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Beginner

Key capabilities

  • Generate SQL queries for single and multi-table operations
  • Inspect database schemas
  • Plan complex JOIN structures
  • Execute queries and format results
  • Troubleshoot SQL syntax errors

How it works

It maps natural language requests to SQL by inspecting table schemas, planning JOINs, and executing queries with safety limits.

Inputs & outputs

You give it
Natural language question about database data
You get back
Executed SQL query and formatted result set

When to use query-writing

  • Write complex JOIN queries
  • Retrieve data for reports
  • Troubleshoot SQL syntax errors
  • Filter records across multiple tables

About this skill

Query Writing Skill

Workflow for Simple Queries

For straightforward questions about a single table:

  1. Identify the table - Which table has the data?
  2. Get the schema - Use sql_db_schema to see columns
  3. Write the query - SELECT relevant columns with WHERE/LIMIT/ORDER BY
  4. Execute - Run with sql_db_query
  5. Format answer - Present results clearly

Workflow for Complex Queries

For questions requiring multiple tables:

1. Plan Your Approach

Use write_todos to break down the task:

  • Identify all tables needed
  • Map relationships (foreign keys)
  • Plan JOIN structure
  • Determine aggregations

2. Examine Schemas

Use sql_db_schema for EACH table to find join columns and needed fields.

3. Construct Query

  • SELECT - Columns and aggregates
  • FROM/JOIN - Connect tables on FK = PK
  • WHERE - Filters before aggregation
  • GROUP BY - All non-aggregate columns
  • ORDER BY - Sort meaningfully
  • LIMIT - Default 5 rows

4. Validate and Execute

Check all JOINs have conditions, GROUP BY is correct, then run query.

Example: Revenue by Country

SELECT
    c.Country,
    ROUND(SUM(i.Total), 2) as TotalRevenue
FROM Invoice i
INNER JOIN Customer c ON i.CustomerId = c.CustomerId
GROUP BY c.Country
ORDER BY TotalRevenue DESC
LIMIT 5;

Error Recovery

If a query fails or returns unexpected results:

  1. Empty results — Verify column names and WHERE conditions against the schema; check for case sensitivity or NULL values
  2. Syntax error — Re-examine JOINs, GROUP BY completeness, and alias references
  3. Timeout — Add stricter WHERE filters or LIMIT to reduce result set, then refine

Quality Guidelines

  • Query only relevant columns (not SELECT *)
  • Always apply LIMIT (5 default)
  • Use table aliases for clarity
  • For complex queries: use write_todos to plan
  • Never use DML statements (INSERT, UPDATE, DELETE, DROP)

When not to use it

  • When the user requests DML statements like INSERT, UPDATE, or DELETE

Prerequisites

Access to database schemaDefined database connection

Limitations

  • Limited to read-only operations
  • Requires schema access to generate accurate queries

How it compares

It automates the entire query lifecycle from schema inspection to result formatting rather than requiring manual SQL writing.

Compared to similar skills

query-writing side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
query-writing (this skill)75moNo flagsBeginner
sql-queries185moNo flagsIntermediate
senior-data-engineer217moReviewAdvanced
powerbi-modeling116moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

sql-queries

anthropics

Write correct, performant SQL across all major data warehouse dialects (Snowflake, BigQuery, Databricks, PostgreSQL, etc.). Use when writing queries, optimizing slow SQL, translating between dialects, or building complex analytical queries with CTEs, window functions, or aggregations.

1888

senior-data-engineer

davila7

World-class data engineering skill for building scalable data pipelines, ETL/ELT systems, and data infrastructure. Expertise in Python, SQL, Spark, Airflow, dbt, Kafka, and modern data stack. Includes data modeling, pipeline orchestration, data quality, and DataOps. Use when designing data architectures, building data pipelines, optimizing data workflows, or implementing data governance.

2179

powerbi-modeling

github

Power BI semantic modeling assistant for building optimized data models. Use when working with Power BI semantic models, creating measures, designing star schemas, configuring relationships, implementing RLS, or optimizing model performance. Triggers on queries about DAX calculations, table relationships, dimension/fact table design, naming conventions, model documentation, cardinality, cross-filter direction, calculation groups, and data model best practices. Always connects to the active model first using power-bi-modeling MCP tools to understand the data structure before providing guidance.

1161

data-quality-frameworks

wshobson

Implement data quality validation with Great Expectations, dbt tests, and data contracts. Use when building data quality pipelines, implementing validation rules, or establishing data contracts.

628

fuzzy-matching

dadbodgeoff

Multi-stage fuzzy matching pipeline for entity reconciliation. PostgreSQL trigram pre-filter, salient overlap check, and multi-factor similarity scoring.

825

data-engineer

sickn33

Build scalable data pipelines, modern data warehouses, and real-time streaming architectures. Implements Apache Spark, dbt, Airflow, and cloud-native data platforms. Use PROACTIVELY for data pipeline design, analytics infrastructure, or modern data stack implementation.

325

Search skills

Search the agent skills registry