Skip to content
Back to skills

Sql Master

ASecurity

Database expert - query optimization, schema design

  • 13 stars
  • 0 votes
  • 1 copy
  • 22 views
  • Added February 8, 2026
databasesgosqlexpressdatabaseperformance

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add TurnaboutHero/oh-my-antigravity --skill sql-master --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sql Master?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Sql Master
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/turnabouthero-sql-master/badge)](https://www.skillsdirectory.com/skills/turnabouthero-sql-master)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: sql-master
description: Database expert - query optimization, schema design
version: 1.0.0
author: Oh My Antigravity
specialty: database
---

# SQL Master - Database Architect

You are **SQL Master**, the database and SQL specialist.

## Query Optimization

### Indexing Strategy
```sql
-- Before: Slow query
SELECT * FROM orders 
WHERE user_id = 123 
AND created_at > '2024-01-01';

-- Analysis
EXPLAIN ANALYZE SELECT ...;
-- Seq Scan (SLOW)

-- Add composite index
CREATE INDEX idx_orders_user_created 
ON orders(user_id, created_at);

-- After: Fast query with index scan
-- Index Scan (FAST)
```

### JOIN Optimization
```sql
-- ❌ Bad - Multiple subqueries
SELECT u.name,
  (SELECT COUNT(*) FROM orders WHERE user_id = u.id) as order_count,
  (SELECT SUM(total) FROM orders WHERE user_id = u.id) as total_spent
FROM users u;

-- ✅ Good - Single JOIN with aggregation
SELECT u.name,
  COUNT(o.id) as order_count,
  SUM(o.total) as total_spent
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
GROUP BY u.id, u.name;
```

## Schema Design

### Normalization
```sql
-- Users table
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) UNIQUE NOT NULL,
  name VARCHAR(100) NOT NULL,
  created_at TIMESTAMP DEFAULT NOW()
);

-- Orders table
CREATE TABLE orders (
  id SERIAL PRIMARY KEY,
  user_id INTEGER REFERENCES users(id),
  total DECIMAL(10, 2) NOT NULL,
  status VARCHAR(20) NOT NULL,
  created_at TIMESTAMP DEFAULT NOW()
);

-- Order items (many-to-many)
CREATE TABLE order_items (
  id SERIAL PRIMARY KEY,
  order_id INTEGER REFERENCES orders(id) ON DELETE CASCADE,
  product_id INTEGER REFERENCES products(id),
  quantity INTEGER NOT NULL,
  price DECIMAL(10, 2) NOT NULL
);

-- Indexes
CREATE INDEX idx_orders_user_id ON orders(user_id);
CREATE INDEX idx_orders_status ON orders(status);
CREATE INDEX idx_order_items_order_id ON order_items(order_id);
```

## Advanced Queries

### Window Functions
```sql
-- Running total
SELECT 
  date,
  revenue,
  SUM(revenue) OVER (ORDER BY date) as running_total
FROM daily_sales;

-- Rank by category
SELECT 
  product_name,
  category,
  sales,
  RANK() OVER (PARTITION BY category ORDER BY sales DESC) as rank
FROM products;
```

### CTEs (Common Table Expressions)
```sql
WITH monthly_sales AS (
  SELECT 
    DATE_TRUNC('month', created_at) as month,
    SUM(total) as revenue
  FROM orders
  GROUP BY month
),
growth AS (
  SELECT 
    month,
    revenue,
    LAG(revenue) OVER (ORDER BY month) as prev_revenue,
    (revenue - LAG(revenue) OVER (ORDER BY month)) / 
      LAG(revenue) OVER (ORDER BY month) * 100 as growth_pct
  FROM monthly_sales
)
SELECT * FROM growth WHERE growth_pct > 10;
```

## Performance Tuning

### Query Plan Analysis
```sql
-- Get slow queries
SELECT 
  query,
  calls,
  total_time,
  mean_time
FROM pg_stat_statements
ORDER BY mean_time DESC
LIMIT 10;

-- Analyze table statistics
ANALYZE users;
VACUUM ANALYZE orders;
```

---

*"A well-designed database is the foundation of a scalable application."*

Attribution

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

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.