Skip to content
OpenSmartRoute
Skillv1.0.0

sql-expert

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

by personamanagmentlayer(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from personamanagmentlayer/pcl (stdlib/data/sql-expert/SKILL.md). Install upstream with npx skills add personamanagmentlayer/pcl --skill sql-expert. Copyright stays with the author (Apache-2.0).

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

-- 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

-- 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

-- 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

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

-- 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 — Database Design, Advanced Queries, Indexes and Performance, Transactions and Concurrency, Advanced Features

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/personamanagmentlayer-pcl-sql-expert/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

personamanagmentlayer-pcl-sql-expert.ocm.jsonjson
{
  "ocm": "1",
  "id": "personamanagmentlayer-pcl-sql-expert",
  "kind": "skill",
  "name": "sql-expert",
  "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.",
  "publisher": "personamanagmentlayer",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "data_analysis",
      "coding"
    ],
    "tags": [
      "skill-md",
      "sql",
      "database",
      "postgresql",
      "mysql",
      "query-optimization",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "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."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/personamanagmentlayer/pcl",
      "path": "stdlib/data/sql-expert/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/personamanagmentlayer/pcl/blob/HEAD/stdlib/data/sql-expert/SKILL.md",
      "key": "personamanagmentlayer/pcl/stdlib/data/sql-expert/SKILL.md"
    },
    "allowed_tools": [
      "Read",
      "Write",
      "Edit",
      "Bash(psql:*, mysql:*, sqlite3:*)",
      "Glob",
      "Grep"
    ],
    "license": "Apache-2.0"
  },
  "instructions": "# SQL Expert\n\nYou 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.\n\n## Best Practices\n\n### 1. Use Prepared Statements\n\n```sql\n-- Prevent SQL injection\n-- Bad (vulnerable)\nquery = \"SELECT * FROM users WHERE email = '\" + userInput + \"'\";\n\n-- Good (safe)\nPREPARE stmt FROM 'SELECT * FROM users WHERE email = ?';\nEXECUTE stmt USING @email;\n```\n\n### 2. Normalize Data Appropriately\n\n```\n1NF: Atomic values, no repeating groups\n2NF: 1NF + no",
  "cost": {
    "context_tokens": 669
  }
}

Fetch it by URL: GET /api/v1/registry/personamanagmentlayer-pcl-sql-expert/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.