How to Use Sql Pro Skill in Claude Code for Beginners
Purpose
This post demonstrates how to use the Sql Pro skill in Claude Code for database development and SQL query optimization.
Environment
- Claude Code with claude-skills plugin
- PostgreSQL 14+
- MySQL 8.0+ (optional)
- Basic SQL knowledge
What is Sql Pro?
The Sql Pro skill provides specialized assistance for database development, SQL query writing, and database optimization. When I work with complex SQL queries, database schema design, or performance optimization, this skill gives me targeted help instead of general coding assistance.
There are 4 main benefits:
Query optimization: Helps write efficient SQL queriesSchema design: Assists with database structure planningDebugging: Identifies and fixes SQL syntax errorsBest practices: Enforces database-specific patterns
I will use Sql Pro when I need to write complex queries, optimize database performance, or design new database schemas.
Installation and Setup
First, I need to install the claude-skills plugin if I haven’t already:
# Navigate to Claude Code plugins directorycd ~/.claude
# Clone the skills repositorygit clone https://github.com/jeffallan/claude-skills.git skills
# Verify installationls skills/The output should show the skills directory structure with various skill folders including postgres-patterns and clickhouse-io.
Now I need to check if Sql Pro is available in my skills list:
# List available skillsls ~/.claude/skills/I should see database-related skills. Sql Pro functionality is typically provided through specialized skills like postgres-patterns for PostgreSQL or clickhouse-io for ClickHouse databases.
Core Usage Patterns
Basic Invocation
When I want to use Sql Pro, I invoke it through the Skill tool with specific database-related tasks:
Use postgres-patterns to optimize this query:SELECT * FROM users WHERE email = '[email protected]';The skill then analyzes my query and suggests improvements:
-- Recommended optimizationCommon Trigger Phrases
I use these phrases to invoke Sql Pro capabilities:
- “Use postgres-patterns to design a schema for…”
- “Use clickhouse-io for analytics query optimization”
- “Use postgres-patterns to write a complex join query”
- “Use postgres-patterns to add indexes to this table”
Typical Use Cases
Query Writing:
When I ask: “Use postgres-patterns to write a query that finds duplicate emails in the users table”
I get:
SELECT email, COUNT(*) as countFROM usersGROUP BY emailHAVING COUNT(*) > 1;Schema Design:
When I ask: “Use postgres-patterns to design a schema for an e-commerce order system”
I get table structures with proper relationships, indexes, and constraints.
Practical Examples
Example 1: Query Optimization
When I have a slow query, I use Sql Pro to optimize it.
Before:
SELECT * FROM orders oJOIN customers c ON o.customer_id = c.idWHERE o.order_date > '2026-01-01'ORDER BY c.name;I ask: “Use postgres-patterns to optimize this query for performance”
After:
SELECT o.id, o.order_date, c.name, c.emailFROM orders oJOIN customers c ON o.customer_id = c.idWHERE o.order_date > '2026-01-01'ORDER BY c.name, o.order_date;
-- Recommended indexCREATE INDEX idx_orders_customer_date ON orders(customer_id, order_date);The optimization includes:
- Selecting only needed columns instead of
* - Adding compound index on frequently filtered columns
- Proper ordering for efficient sorting
Example 2: Schema Design Pattern
When I need to create a new table, I use Sql Pro for proper structure.
I ask: “Use postgres-patterns to create a user_sessions table with audit fields”
The skill provides:
CREATE TABLE user_sessions ( id BIGSERIAL PRIMARY KEY, user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE, token VARCHAR(255) NOT NULL UNIQUE, ip_address INET, user_agent TEXT, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), last_accessed_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), expires_at TIMESTAMPTZ NOT NULL);
-- Indexes for common queriesCREATE INDEX idx_sessions_user_id ON user_sessions(user_id);CREATE INDEX idx_sessions_token ON user_sessions(token);CREATE INDEX idx_sessions_expires_at ON user_sessions(expires_at);
-- Composite index for session lookupCREATE INDEX idx_sessions_user_expires ON user_sessions(user_id, expires_at);
-- Automatically clean up expired sessionsCREATE INDEX idx_sessions_expired ON user_sessions(expires_at)WHERE expires_at < NOW();This includes:
- Proper foreign key relationships
- Timestamps for audit trails
- Strategic indexes for performance
- Partial index for cleanup queries
Example 3: Best Practices for Joins
When working with complex joins, I use Sql Pro to write efficient queries.
I ask: “Use postgres-patterns to write a query showing top 5 customers by total order amount”
The result:
SELECT c.id, c.name, c.email, SUM(o.total_amount) as total_spent, COUNT(o.id) as order_countFROM customers cJOIN orders o ON c.id = o.customer_idWHERE o.status = 'completed' AND o.order_date >= '2026-01-01'GROUP BY c.id, c.name, c.emailORDER BY total_spent DESCLIMIT 5;The query includes:
- Explicit column selection
- Proper JOIN syntax
- Meaningful WHERE clause
- Correct GROUP BY usage
- Ordered results with LIMIT
Best Practices
DO
Use Specific Skills:
- Invoke
postgres-patternsfor PostgreSQL-specific tasks - Use
clickhouse-iofor ClickHouse analytics queries - Specify database type in your request
Provide Context:
- Include table structure when asking for queries
- Mention row counts when discussing optimization
- State your database version
Test Incrementally:
- Start with simple queries
- Add complexity gradually
- Verify each step with EXPLAIN ANALYZE
DON’T
Don’t Use Generic Requests:
- Bad: “Write a SQL query”
- Good: “Use postgres-patterns to write a query that joins orders and customers”
Don’t Skip Testing:
- Always test generated queries
- Check execution plans
- Verify results match expectations
Don’t Ignore Database Differences:
- PostgreSQL has different syntax than MySQL
- ClickHouse requires specific patterns
- Always specify your database type
Related Skills and Resources
Complementary Skills
- jpa-patterns: For JPA/Hibernate ORM mapping
- backend-patterns: For API integration with databases
- springboot-patterns: For Spring Data JPA integration
Official Resources
Community Resources
Summary
In this post, I showed how to use the Sql Pro skill in Claude Code through postgres-patterns and clickhouse-io skills. I covered installation, basic invocation patterns, practical examples for query optimization and schema design, and best practices for database development. The key point is that using database-specific skills gives me targeted assistance for SQL development, resulting in more efficient queries and better database designs.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments