table-normalization-1nf
Table Normalization (1NF Violations)
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 18
- Forks
- 6
01 前言 Front Matter
- name
- table-normalization-1nf
- metadata
- { "original-index": 22, "short-description": "Table Normalization (1NF Violations)" }
- description
- Table Normalization (1NF Violations)
02 资源文件 1
- 参考文档skill.json158 B
03 SKILL.md 正文
Table Normalization (1NF Violations)
What
Breaking repeating column groups (e.g., PreferredDate1, PreferredDate2,
PreferredDate3) into properly normalized child tables with foreign keys.
This resolves First Normal Form (1NF) violations.
Why
Repeating columns create:
- Query complexity: WHERE clauses need
ORacross N columns - Schema rigidity: adding a 4th preference requires ALTER TABLE
- NULL proliferation: most rows only use 1-2 of N slots
- Index waste: each column needs its own index for searchability
A normalized child table (ApplicantPreferredDates) with one row per preference
eliminates all of these problems.
How
Step 1: Identify the repeating group
-- Columns like: PreferredDate1_Start, PreferredDate1_End,
-- PreferredDate2_Start, PreferredDate2_End, ...
SELECT column_name FROM information_schema.columns
WHERE table_name = 'Applicant'
AND column_name LIKE 'Preferred%'
ORDER BY ordinal_position;
Step 2: Create the child table
CREATE TABLE public."ApplicantPreferredDate" (
"Id" bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
"ApplicantId" bigint NOT NULL
REFERENCES public."Applicant"("ApplicantId") ON DELETE CASCADE,
"Preference" smallint NOT NULL CHECK ("Preference" BETWEEN 1 AND 3),
"StartDate" timestamptz,
"EndDate" timestamptz,
UNIQUE ("ApplicantId", "Preference")
);
Step 3: Migrate existing data
INSERT INTO public."ApplicantPreferredDate"
("ApplicantId", "Preference", "StartDate", "EndDate")
SELECT "ApplicantId", 1, "FirstPreferredSD", "FirstPreferredED"
FROM public."Applicant"
WHERE "FirstPreferredSD" IS NOT NULL
UNION ALL
SELECT "ApplicantId", 2, "SecondPreferredSD", "SecondPreferredED"
FROM public."Applicant"
WHERE "SecondPreferredSD" IS NOT NULL
UNION ALL
SELECT "ApplicantId", 3, "ThirdPreferredSD", "ThirdPreferredED"
FROM public."Applicant"
WHERE "ThirdPreferredSD" IS NOT NULL;
Step 4: Update procedures to use child table
Replace direct column references with JOINs or subqueries against the child table.
Step 5: (Later) Drop the old columns
-- Only after app code is fully migrated
ALTER TABLE public."Applicant"
DROP COLUMN "FirstPreferredSD",
DROP COLUMN "FirstPreferredED",
-- ... etc.
When to Use
- Tables with numbered/suffixed column groups (Date1, Date2, Date3)
- Tables with arrays stored as separate columns
- After audit findings flag 1NF violations
Where We Used It
- ****: Normalized Applicant preferred dates and preferred locations
from repeating columns into
ApplicantPreferredDateandApplicantPreferredLocationchild tables
Related Skills
- Skill #07 (Backward Compatibility) -- keep old columns during transition
- Skill #09 (Foreign Key Constraints) -- FK from child table to parent
- Skill #14 (Research Checklist) -- find all procedures referencing old columns
References
- PostgreSQL Best Practices -- see "Schema design and data types" section
Gotchas
- Data migration is the hard part -- handle NULLs, duplicates, and edge cases
- Keep old columns during transition (backward compatibility, Skill #07)
- Update ALL procedures that reference the old columns (Skill #14, #08)
- The child table needs proper indexes (FK column, composite lookups)
- Application code must be updated to INSERT into the child table instead of the parent's repeating columns
*Category: DDL | Origin: *
04 同仓库更多 Skills
yeet
Use only when the user explicitly asks to stage, commit, push, and open a GitHub pull request in one flow using the GitHub CLI (`gh`).
wrangler
Cloudflare Workers CLI for deploying, developing, and managing Workers, KV, R2, D1, Vectorize, Hyperdrive, Workers AI, Containers, Queues, Workflows, Pipelines, and Secrets Store. Load before running wrangler commands to ensure correct syntax and best practices. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.
workspace-skill-discovery
Discover and include ALL skills across the workspace — not just global ones. Use at the start of every session or when the user asks about available skills. Ensures project-level skills (under .claude/skills/ or skills/ in any repo) are never missed.
workers-best-practices
Reviews and authors Cloudflare Workers code against production best practices. Load when writing new Workers, reviewing Worker code, configuring wrangler.jsonc, or checking for common Workers anti-patterns (streaming, floating promises, global state, secrets, bindings, observability). Biases towards retrieval from Cloudflare docs over pre-trained knowledge.
winui-app
Create, build and design WinUI 3 desktop apps with C# and the Windows App SDK following Microsoft's official guidance and CommunityToolkit. Covers XAML, navigation, theming, accessibility and deployment.
windows-brain-script-portability
Scripts in ~/.claude/scripts/ that run on a Windows brain: use the python3.cmd shim and not bare python3, and reconfigure stdout to UTF-8 if you print symbols. Use it when writing a brain script or triaging a Windows-only crash.