-- Users table
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255),
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
-- Indexes
CREATE INDEX idx_users_email ON users(email);
Index Strategy
Query Pattern
Index Type
WHERE email = ?
Single column
WHERE status = ? AND created > ?
Composite
ORDER BY created_at DESC
B-tree (default)
Full text search
GIN
Migration Safety
-- Always add columns as nullable first
ALTER TABLE users ADD COLUMN phone VARCHAR(20);
-- Backfill data
UPDATE users SET phone = 'unknown' WHERE phone IS NULL;
-- Make not nullable
ALTER TABLE users ALTER COLUMN phone SET NOT NULL;
Checklist
Use UUID for primary keys
Add timestamps (created_at, updated_at)
Create indexes for query patterns
Write safe migrations (backfill, nullable first)
Use EXPLAIN ANALYZE
Set up connection pooling
1---2name: sql-database3description: SQL Database Mastery4---5# SQL Database Mastery67## Schema Design89```sql10-- Users table11CREATE TABLE users (12 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),13 email VARCHAR(255) UNIQUE NOT NULL,14 name VARCHAR(255),15 created_at TIMESTAMP DEFAULT NOW(),16 updated_at TIMESTAMP DEFAULT NOW()17);1819-- Indexes20CREATE INDEX idx_users_email ON users(email);21```2223## Index Strategy2425| Query Pattern | Index Type |26|--------------|-------------|27| WHERE email = ? | Single column |28| WHERE status = ? AND created > ? | Composite |29| ORDER BY created_at DESC | B-tree (default) |30| Full text search | GIN |3132## Migration Safety3334```sql35-- Always add columns as nullable first36ALTER TABLE users ADD COLUMN phone VARCHAR(20);3738-- Backfill data39UPDATE users SET phone = 'unknown' WHERE phone IS NULL;4041-- Make not nullable42ALTER TABLE users ALTER COLUMN phone SET NOT NULL;43```4445## Checklist4647- [ ] Use UUID for primary keys48- [ ] Add timestamps (created_at, updated_at)49- [ ] Create indexes for query patterns50- [ ] Write safe migrations (backfill, nullable first)51- [ ] Use EXPLAIN ANALYZE52- [ ] Set up connection pooling
Run npx skillmds@latest add modbender/sql-database in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
SQL Database Mastery It is listed under Data & Analytics on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
modbender (@modbender) published this skill. Their other Agent Skills are listed on their SkillMD profile.