Moving a Repeated Attribute into a Related Table

A separate table can keep repeated facts in one authoritative location and let several rows refer to them.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a venue rename
  2. Keep intentional snapshots
  3. Keep repeated values as rows owned by their entity
  4. Preserve ordering or preference when it is meaningful

Trace a venue rename

If every booking stores the venue's current display name separately, a rename may require many edits. Giving the venue a row and storing its ID in bookings makes one canonical name available. One-to-many relationships describe this arrangement.

Keep intentional snapshots

A historical booking may need the venue name it actually displayed when accepted. Treat that saved fact as a snapshot rather than current venue metadata. Entity identity across edits names the distinction.[1][2]

Keep repeated values as rows owned by their entity

A contact can have zero, one or many phone numbers. Columns named phone1 and phone2 impose a fixed limit and complicate querying every number. A separate phone table can store one number per contact and include its type. See one-to-many data modeling.

Contact 9: River
Phone row (contact 9, office, value A)
Phone row (contact 9, mobile, value B)
Contact without phones still exists

Preserve ordering or preference when it is meaningful

A preferred phone flag or explicit order can identify the first display choice. Model whether duplicates are allowed. Test three numbers, no numbers and changing one preferred value.

References

  1. PostgreSQL Global Development Group, Data Definition ↩
  2. PostgreSQL Global Development Group, SQL Language Tutorial ↩