-- 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 Mastery4metadata:5 source: https://skillmd.com/skills/dvcrn/sql-database6---7# SQL Database Mastery89## Schema Design1011```sql12-- Users table13CREATE TABLE users (14 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),15 email VARCHAR(255) UNIQUE NOT NULL,16 name VARCHAR(255),17 created_at TIMESTAMP DEFAULT NOW(),18 updated_at TIMESTAMP DEFAULT NOW()19);2021-- Indexes22CREATE INDEX idx_users_email ON users(email);23```2425## Index Strategy2627| Query Pattern | Index Type |28|--------------|-------------|29| WHERE email = ? | Single column |30| WHERE status = ? AND created > ? | Composite |31| ORDER BY created_at DESC | B-tree (default) |32| Full text search | GIN |3334## Migration Safety3536```sql37-- Always add columns as nullable first38ALTER TABLE users ADD COLUMN phone VARCHAR(20);3940-- Backfill data41UPDATE users SET phone = 'unknown' WHERE phone IS NULL;4243-- Make not nullable44ALTER TABLE users ALTER COLUMN phone SET NOT NULL;45```4647## Checklist4849- [ ] Use UUID for primary keys50- [ ] Add timestamps (created_at, updated_at)51- [ ] Create indexes for query patterns52- [ ] Write safe migrations (backfill, nullable first)53- [ ] Use EXPLAIN ANALYZE54- [ ] Set up connection pooling
Run npx get-skill add dvcrn/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. Capability flags: docs only. 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.
dvcrn (@dvcrn) published this skill. Their other Agent Skills are listed on their SkillMD profile.