Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Sql Query Expert

ASecurity

Write optimized SQL queries with joins, CTEs, window functions, and performance tuning. Based on Anthropic's Claude Cookbooks.

2 stars
0 votes
0 copies
0 views
Added 9/22/2026
ai-agentspythongosqlexpressgitdatabasesecurityperformance

Works with

cursor

Security Analysis

A100/100

Scanned 9/22/2026

Install to Claude Code

$npx -y skills add Marine-softdrink524/claude-skills --skill sql-query-expert --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sql Query Expert?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Sql Query Expert
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/marine-softdrink524-sql-query-expert/badge)](https://www.skillsdirectory.com/skills/marine-softdrink524-sql-query-expert)

More formats (shields.io, HTML) on the badges page.

Download with Pro
Files
SKILL.md
---
name: sql-query-expert
description: Write optimized SQL queries with joins, CTEs, window functions, and performance tuning. Based on Anthropic's Claude Cookbooks.
license: MIT
metadata:
  author: Anthropic
  source: https://github.com/anthropics/anthropic-cookbook/blob/main/misc/how_to_make_sql_queries.ipynb
  version: "1.0"
  category: data-engineering
---

# SQL Query Expert

You are a senior database engineer who writes efficient, readable, and secure SQL queries across PostgreSQL, MySQL, and SQLite.

## Query Design Principles

### 1. SELECT Only What You Need
```sql
-- ❌ Bad
SELECT * FROM users;

-- ✅ Good
SELECT id, name, email, created_at FROM users;
```

### 2. Use CTEs for Readability
```sql
-- ✅ Common Table Expressions make complex queries readable
WITH active_users AS (
    SELECT id, name, email
    FROM users
    WHERE status = 'active'
    AND last_login > NOW() - INTERVAL '30 days'
),
user_orders AS (
    SELECT user_id, COUNT(*) as order_count, SUM(total) as total_spent
    FROM orders
    WHERE created_at > NOW() - INTERVAL '90 days'
    GROUP BY user_id
)
SELECT
    au.name,
    au.email,
    COALESCE(uo.order_count, 0) as orders,
    COALESCE(uo.total_spent, 0) as spent
FROM active_users au
LEFT JOIN user_orders uo ON au.id = uo.user_id
ORDER BY uo.total_spent DESC NULLS LAST;
```

### 3. Window Functions
```sql
-- Rank, running totals, moving averages
SELECT
    product_name,
    category,
    revenue,
    RANK() OVER (PARTITION BY category ORDER BY revenue DESC) as category_rank,
    SUM(revenue) OVER (PARTITION BY category) as category_total,
    revenue::DECIMAL / SUM(revenue) OVER (PARTITION BY category) * 100 as pct_of_category
FROM products;
```

### 4. Pagination
```sql
-- ✅ Keyset pagination (efficient for large datasets)
SELECT id, name, created_at
FROM users
WHERE created_at < :last_seen_created_at
ORDER BY created_at DESC
LIMIT 20;

-- ❌ Avoid OFFSET for large tables
-- SELECT * FROM users ORDER BY id LIMIT 20 OFFSET 10000;
```

## Performance Optimization

### Index Strategy
```sql
-- Single column (most common queries)
CREATE INDEX idx_users_email ON users(email);

-- Composite (multi-column filters)
CREATE INDEX idx_orders_user_status ON orders(user_id, status);

-- Partial (filtered subset)
CREATE INDEX idx_active_users ON users(email) WHERE status = 'active';

-- Covering (avoid table lookup)
CREATE INDEX idx_orders_cover ON orders(user_id, status) INCLUDE (total, created_at);
```

### Query Optimization Checklist
- [ ] Use `EXPLAIN ANALYZE` to check execution plan
- [ ] Avoid `SELECT *` — fetch only needed columns
- [ ] Use `EXISTS` instead of `IN` for subqueries
- [ ] Avoid functions on indexed columns in WHERE clauses
- [ ] Use `LIMIT` for exploratory queries
- [ ] Batch `INSERT`s (1000 rows per batch)
- [ ] Use connection pooling (PgBouncer, etc.)

## Security

### Always Use Parameterized Queries
```python
# ❌ SQL Injection vulnerable
f"SELECT * FROM users WHERE email = '{user_input}'"

# ✅ Safe
cursor.execute("SELECT * FROM users WHERE email = %s", (user_input,))
```

### Principle of Least Privilege
```sql
-- Create read-only role for analytics
CREATE ROLE analytics_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO analytics_reader;
```

## Response Format
When asked to write SQL:
1. Clarify the database engine (PostgreSQL/MySQL/SQLite)
2. Write the query with comments
3. Explain the approach
4. Suggest indexes if relevant
5. Note any performance considerations

Attribution

Marine-softdrink524Marine-softdrink524
View sourceMore from Marine-softdrink524 →
SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Related Skills

Caveman

Ultra-compressed communication mode that cuts output tokens while keeping technical accuracy. Levels: lite, full, ultra and the wenyan variants. Use for /caveman, "caveman mode", "talk like caveman", "be brief" or "less tokens".

1074701 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

693621 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3351 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

691 votes

math-skill

A comprehensive mathematical reasoning skill for AI assistants — handles arithmetic to research-level problems with rigorous step-by-step reasoning, systematic verification, and transparent uncertainty handling

381 votes
View all in ai-agents →