Skip to main content
skill CX Codex

sql-expert — Claude Code skill: database design and query optimization

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

Apache-2.0 1 installs ★ 45 updated 2026-10-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add personamanagmentlayer/pcl --skill sql-expert -a claude-code
Open on GitHub

What sql-expert 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.

What it helps with

  • 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 for the agent

  • 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

How to install sql-expert

1Skills CLI (Vercel)

npx skills add personamanagmentlayer/pcl --skill sql-expert -a claude-code

2Manually: put the files in place

~/.claude/skills/sql-expert/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/sql-expert/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about sql-expert

How do I install sql-expert in Claude Code?

Run npx skills add personamanagmentlayer/pcl --skill sql-expert -a claude-code, then verify it in ~/.claude/skills/sql-expert/SKILL.md.

What does sql-expert do?

It provides expert support for SQL: database design, query optimization, indexing strategies, transactions, and administration of PostgreSQL, MySQL, and SQL Server.

Which databases does it support?

PostgreSQL, MySQL, and SQL Server. The skill adapts syntax and strategies to each platform's capabilities and quirks.

Source text

SKILL.md · Apache-2.0
---
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
8. **Test Thoroughly**: Test queries with production-like data volumes

Always write efficient, maintainable SQL that ensures data integrity and performs well at scale.

## Reference Documentation

Detailed material lives alongside this skill and is read on demand:

- [Core Expertise](references/CORE_CONCEPTS.md) — Database Design, Advanced Queries, Indexes and Performance, Transactions and Concurrency, Advanced Features

© PCL Team · Apache-2.0 · personamanagmentlayer/pcl

Similar skills

All skills for Data and databases →

From the same set104

The whole set →
codeql-expert The codeql-expert skill guides CodeQL database setup, custom query writing, and vulnerability scans. Use it for SAST tasks, taint tracking, and GitHub security workflows. CX Codex +1 174installs skill-creator-expert skill-creator-expert guides you through designing, writing and checking PCL skills, from domain analysis to a frontmatter template and a quality checklist. CX Codex +1 173installs django-expert django-expert guides full-stack Django development covering ORM models, views, forms, authentication, and Django REST Framework APIs. CX Codex +1 172installs graphql-expert graphql-expert is a Claude Code skill for GraphQL schema design, resolvers, and subscriptions, with guidance on Apollo federation and N+1 queries. CX Codex +1 169installs data-mesh-expert data-mesh-expert walks the agent through data mesh work: domains own their data, products ship with contracts, governance is federated and the platform serves itself. CX Codex +1 168installs swift-expert swift-expert guides an agent through Swift work for iOS and macOS, from SwiftUI screens to async code. Use it when a task involves Combine or modern Swift features. CX Codex +1 163installs linkerd-expert linkerd-expert — a Linkerd skill for Kubernetes work: the agent installs the mesh, injects the proxy, pulls linkerd viz metrics and writes access policies. CX Codex +1 162installs pcl-expert pcl-expert — a skill for Persona Control Language: persona, team and workflow declarations, the compiler pipeline, the pcl toolchain. Useful when the agent edits .pcl files or the compiler itself. CX Codex +1 160installs

Project sponsors

Companies that keep this analytics open