Home >Database >Mysql Tutorial >Subtype or Supertype: Which Database Design Best Handles Polymorphic Data?
In database design, the decision arises whether to use subtypes or not. Subtypes are used when a specific type of data has additional attributes or properties that distinguish it from other types. This approach involves creating separate tables for each subtype, leading to a potentially large number of tables.
Consider a database with three main tables: BOOKS, ARTICLES, and NOTES. Each book and article can have multiple notes. The initial design assigned notes to a single NOTES table with columns:
An alternative design proposes using five tables:
This design keeps book and article notes separate, simplifying data management.
Pros of Subtype Design (Existing Design):
Cons of Subtype Design:
Pros of Supertype Design (Alternative Design):
A modified approach suggests using a supertype Publication table with two subtypes: Book and Article. This model would allow for a single Note table with a foreign key to Publication, enabling joins across all publication types (Book, Article, Magazine, etc.).
The above is the detailed content of Subtype or Supertype: Which Database Design Best Handles Polymorphic Data?. For more information, please follow other related articles on the PHP Chinese website!