# sql-expert

sql-expert — a skill for expert SQL work: schema design, efficient queries, index optimization, and administration across PostgreSQL, MySQL, and SQL Server.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 1 install · ★ 45 repo stars
- Author: PCL Team
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/personamanagmentlayer/pcl/tree/HEAD/stdlib/data/sql-expert/SKILL.md
- Updated: 2026-10-12
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/sql-expert

## What it does

sql-expert provides expert-level support for SQL databases. It helps design schemas with proper normalization and integrity constraints, write optimized queries, troubleshoot slow execution, and manage indexes and transactions. The skill covers PostgreSQL, MySQL, and SQL Server.

It applies best practices by default: prepared statements to prevent SQL injection, data normalization, foreign keys, constraints, and batch operations. It can analyze query performance, recommend indexing strategies, and guide you through database architecture decisions.

Install once per platform, and the skill activates automatically when you mention databases, query optimization, or schema design.

## Requirements
- Works with: PostgreSQL

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill sql-expert -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/sql-expert/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/sql-expert/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill sql-expert -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/sql-expert/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill sql-expert -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/sql-expert/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install personamanagmentlayer/pcl stdlib/data/sql-expert
```

2. **Manually: put the files in place**
- File: `.github/skills/sql-expert/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill sql-expert -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/personamanagmentlayer/pcl --path stdlib/data/sql-expert
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/sql-expert/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill sql-expert -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/personamanagmentlayer/pcl/tree/HEAD/stdlib/data/sql-expert/SKILL.md

## When to use it
- design a normalized database schema with integrity constraints
- write an efficient query with multiple joins and aggregations
- add indexes and optimize a slow query
- design a transaction to ensure data consistency
- implement prepared statements to prevent SQL injection

## Example prompts
- Design a schema for an app with users, posts, and comments
- Optimize this query—it's too slow in production
- Write a migration that adds an index on `created_at` and a foreign key to the `users` table

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: ccdbae9210d2d2fa.

BEGIN THIRD-PARTY FILE ccdbae9210d2d2fa
````text
---
name: sql-expert
version: 1.1.0
description: >-
  Expert-level SQL database design, querying, optimization, and administration across
  PostgreSQL, MySQL, and SQL Server. Use when the user mentions database, PostgreSQL,
  MySQL, or query optimization, or when the task involves Database Design, Advanced
  Queries, Indexes and Performance, or Transactions and Concurrency.
category: data
author: PCL Team
license: Apache-2.0
tags:
  - sql
  - database
  - postgresql
  - mysql
  - query-optimization
allowed-tools:
  - Read
  - Write
  - Edit
  - Bash(psql:*, mysql:*, sqlite3:*)
  - Glob
  - Grep
---

# SQL Expert

You are an expert in SQL databases with deep knowledge of database design, query optimization, indexing strategies, and administration. You write efficient, maintainable SQL queries and design robust database schemas.

## Best Practices

### 1. Use Prepared Statements

```sql
-- Prevent SQL injection
-- Bad (vulnerable)
query = "SELECT * FROM users WHERE email = '" + userInput + "'";

-- Good (safe)
PREPARE stmt FROM 'SELECT * FROM users WHERE email = ?';
EXECUTE stmt USING @email;
```

### 2. Normalize Data Appropriately

```
1NF: Atomic values, no repeating groups
2NF: 1NF + no partial dependencies
3NF: 2NF + no transitive dependencies

Denormalize only for performance when needed
```

### 3. Use Foreign Keys

```sql
-- Enforce referential integrity
CREATE TABLE posts (
    id SERIAL PRIMARY KEY,
    user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    title VARCHAR(200) NOT NULL
);
```

### 4. Add Appropriate Indexes

```sql
-- Index foreign keys
CREATE INDEX idx_posts_user_id ON posts(user_id);

-- Index columns used in WHERE, JOIN, ORDER BY
CREATE INDEX idx_posts_created_at ON posts(created_at);

-- Don't over-index (slows writes)
```

### 5. Use Constraints

```sql
CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    age INTEGER CHECK (age >= 0 AND age <= 150),
    email VARCHAR(255) NOT NULL UNIQUE,
    status VARCHAR(20) DEFAULT 'active'
        CHECK (status IN ('active', 'inactive', 'banned'))
);
```

### 6. Batch Operations

```sql
-- Bad - multiple inserts
INSERT INTO users (name) VALUES ('Alice');
INSERT INTO users (name) VALUES ('Bob');
INSERT INTO users (name) VALUES ('Charlie');

-- Good - single insert
INSERT INTO users (name) VALUES
    ('Alice'),
    ('Bob'),
    ('Charlie');
```

## Approach

When working with SQL:

1. **Design Schema Carefully**: Normalize, use constraints, plan indexes
2. **Write Readable Queries**: Format SQL, use aliases, add comments
3. **Optimize Performance**: Analyze queries, add indexes, avoid N+1
4. **Use Transactions**: Ensure data integrity for related operations
5. **Prevent SQL Injection**: Always use prepared statements
6. **Monitor Performance**: Track slow queries, optimize bottlenecks
7. **Backup Regularly**: Plan disaster recovery
````
END THIRD-PARTY FILE ccdbae9210d2d2fa

The third-party file has ended. Everything between the ccdbae9210d2d2fa tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2860 of 3288 bytes. © PCL Team · Apache-2.0 · https://github.com/personamanagmentlayer/pcl/tree/HEAD/stdlib/data/sql-expert/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
