
Database Schema Design
- 521 installs
- 305 repo stars
- Updated March 4, 2026
- aj-geddes/useful-ai-prompts
database-schema-design is a Claude Code skill that generates normalized relational database schemas with constraints and performance considerations for developers planning PostgreSQL or MySQL data models.
About
database-schema-design is a skill from aj-geddes/useful-ai-prompts for designing scalable, normalized relational schemas with proper relationships, constraints, and data types. It covers normalization techniques, relationship patterns, and constraint strategies for PostgreSQL and MySQL. Developers reach for database-schema-design when starting greenfield data models, redesigning tables, or planning indexes and foreign keys before writing migrations. The skill outputs table definitions, relationship diagrams in prose, and constraint recommendations suited to transactional application backends.
- Covers 1NF through 5NF normalization techniques with concrete SQL examples
- Designs 1:1, 1:N, and N:N relationship patterns with proper foreign keys
- Includes constraint, index, and trigger planning for data integrity
- Provides PostgreSQL and MySQL specific schema patterns
- Delivers ready-to-apply CREATE TABLE statements and migration guidance
Database Schema Design by the numbers
- 521 all-time installs (skills.sh)
- Ranked #121 of 911 Databases skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill database-schema-designAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 521 |
|---|---|
| repo stars | ★ 305 |
| Last updated | March 4, 2026 |
| Repository | aj-geddes/useful-ai-prompts ↗ |
How do you design a normalized PostgreSQL or MySQL schema?
Generate properly normalized, relational database schemas for PostgreSQL and MySQL with correct constraints and performance considerations.
Who is it for?
Backend developers designing new relational schemas who need normalization, constraints, and PostgreSQL or MySQL specifics.
Skip if: NoSQL document stores, graph databases, or teams that only need query tuning on an existing schema.
When should I use this skill?
A developer asks to design tables, plan a data model, or create a new PostgreSQL or MySQL schema.
What you get
Normalized table definitions, relationship mappings, constraint specifications, and data-type choices for PostgreSQL or MySQL.
- Table schema definitions
- Relationship and constraint specifications
Files
Database Schema Design
Table of Contents
Overview
Design scalable, normalized database schemas with proper relationships, constraints, and data types. Includes normalization techniques, relationship patterns, and constraint strategies.
When to Use
- New database schema design
- Data model planning
- Table structure definition
- Relationship design (1:1, 1:N, N:N)
- Normalization analysis
- Constraint and trigger planning
- Performance optimization at schema level
Quick Start
PostgreSQL - Eliminate Repeating Groups:
-- NOT 1NF: repeating group in single column
CREATE TABLE orders_bad (
id UUID PRIMARY KEY,
customer_name VARCHAR(255),
product_ids VARCHAR(255) -- "1,2,3" - repeating group
);
-- 1NF: separate table for repeating data
CREATE TABLE orders (
id UUID PRIMARY KEY,
customer_name VARCHAR(255),
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE order_items (
id UUID PRIMARY KEY,
order_id UUID NOT NULL,
product_id UUID NOT NULL,
quantity INTEGER NOT NULL,
FOREIGN KEY (order_id) REFERENCES orders(id) ON DELETE CASCADE
);Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| First Normal Form (1NF) | First Normal Form (1NF) |
| Second Normal Form (2NF) | Second Normal Form (2NF) |
| Third Normal Form (3NF) | Third Normal Form (3NF) |
| Entity-Relationship Patterns | Entity-Relationship Patterns |
Best Practices
✅ DO
- Follow established patterns and conventions
- Write clean, maintainable code
- Add appropriate documentation
- Test thoroughly before deploying
❌ DON'T
- Skip testing or validation
- Ignore error handling
- Hard-code configuration values
Entity-Relationship Patterns
Entity-Relationship Patterns
PostgreSQL - One-to-Many:
-- One user has many orders
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE orders (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL,
order_date TIMESTAMP DEFAULT NOW(),
total DECIMAL(10,2),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
INDEX idx_user_id (user_id)
);PostgreSQL - One-to-One:
-- One user has one profile
CREATE TABLE user_profiles (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID UNIQUE NOT NULL,
bio TEXT,
avatar_url VARCHAR(500),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);PostgreSQL - Many-to-Many:
-- Students and courses (many-to-many)
CREATE TABLE students (
id UUID PRIMARY KEY,
name VARCHAR(255)
);
CREATE TABLE courses (
id UUID PRIMARY KEY,
title VARCHAR(255)
);
-- Junction table
CREATE TABLE course_enrollments (
id UUID PRIMARY KEY,
student_id UUID NOT NULL,
course_id UUID NOT NULL,
enrolled_at TIMESTAMP DEFAULT NOW(),
FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE,
FOREIGN KEY (course_id) REFERENCES courses(id) ON DELETE CASCADE,
UNIQUE(student_id, course_id)
);First Normal Form (1NF)
First Normal Form (1NF)
PostgreSQL - Eliminate Repeating Groups:
-- NOT 1NF: repeating group in single column
CREATE TABLE orders_bad (
id UUID PRIMARY KEY,
customer_name VARCHAR(255),
product_ids VARCHAR(255) -- "1,2,3" - repeating group
);
-- 1NF: separate table for repeating data
CREATE TABLE orders (
id UUID PRIMARY KEY,
customer_name VARCHAR(255),
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE order_items (
id UUID PRIMARY KEY,
order_id UUID NOT NULL,
product_id UUID NOT NULL,
quantity INTEGER NOT NULL,
FOREIGN KEY (order_id) REFERENCES orders(id) ON DELETE CASCADE
);Second Normal Form (2NF)
Second Normal Form (2NF)
PostgreSQL - Remove Partial Dependencies:
-- NOT 2NF: non-key attribute depends on part of composite key
CREATE TABLE enrollment_bad (
student_id UUID,
course_id UUID,
professor_name VARCHAR(255), -- depends on course_id only
PRIMARY KEY (student_id, course_id)
);
-- 2NF: separate tables
CREATE TABLE enrollments (
id UUID PRIMARY KEY,
student_id UUID NOT NULL,
course_id UUID NOT NULL,
FOREIGN KEY (student_id) REFERENCES students(id),
FOREIGN KEY (course_id) REFERENCES courses(id),
UNIQUE(student_id, course_id)
);
CREATE TABLE courses (
id UUID PRIMARY KEY,
name VARCHAR(255),
professor_id UUID NOT NULL,
FOREIGN KEY (professor_id) REFERENCES professors(id)
);Third Normal Form (3NF)
Third Normal Form (3NF)
PostgreSQL - Remove Transitive Dependencies:
-- NOT 3NF: transitive dependency (customer_city depends on customer_state)
CREATE TABLE orders_bad (
id UUID PRIMARY KEY,
customer_city VARCHAR(100),
customer_state VARCHAR(50),
state_tax_rate DECIMAL(5,3) -- depends on customer_state
);
-- 3NF: separate tables
CREATE TABLE states (
id UUID PRIMARY KEY,
code VARCHAR(2) UNIQUE,
name VARCHAR(100),
tax_rate DECIMAL(5,3)
);
CREATE TABLE orders (
id UUID PRIMARY KEY,
customer_city VARCHAR(100),
state_id UUID NOT NULL,
FOREIGN KEY (state_id) REFERENCES states(id)
);#!/bin/bash
# validate-schema.sh - Validate database schema
# Usage: ./validate-schema.sh <schema_file>
set -euo pipefail
SCHEMA_FILE="${{1:?Usage: $0 <schema_file>}}"
echo "Validating schema: $SCHEMA_FILE"
# TODO: Add schema validation
# - Check SQL syntax
# - Verify foreign key references
# - Check index definitions
# - Validate naming conventions
# - Check for missing constraints
echo "Schema validation complete."
-- Migration: [description]
-- Created: [date]
-- TODO: Customize for your migration framework
BEGIN;
-- Up migration
-- TODO: Add schema changes
-- CREATE TABLE IF NOT EXISTS ...
-- ALTER TABLE ...
-- Down migration (rollback)
-- TODO: Add rollback statements
-- DROP TABLE IF EXISTS ...
COMMIT;
Related skills
How it compares
Pick database-schema-design for greenfield relational modeling; use migration-specific skills when altering existing production schemas.
FAQ
Which databases does database-schema-design support?
database-schema-design targets PostgreSQL and MySQL relational schemas. The aj-geddes/useful-ai-prompts skill produces normalized tables, relationships, constraints, and data-type recommendations for transactional application backends.
When should database-schema-design be invoked?
database-schema-design should be invoked when creating a new database schema, redesigning tables, or planning data models before migrations. The skill emphasizes normalization, relationship patterns, and constraint strategies.