I'm trying to derive an Entity Relation diagram from a class diagram.
In the class diagram, I have a class Player with one to many relationship to another class Payment. In Payment there is no attribute 'paymentID' and 'playerID' is foreign key. Since the same player ('playerID') can make the same payment many times, I thought of adding an attribute 'paymentID' to the Payment table. Is this right? Will I still follow the requirements? I'm new to all these, thank you for any help.
Database design- diagrams
database-design
Related Question
- Mysql – Relational Database tables
- Database Design – Converting ER Diagrams to SQL or Relational Tables
- Database Design – Structuring an Exam System
- Database Design – Best Way to Represent Team and Player Relationship in ERD
- Database Design – Represent Entity Types in ERD as Relations with Attribute Names
- Foreign Key as Primary Key when “converting” conceptual entity-relationship elements to logical relations
- Database Design – Mapping a 1:1:N Ternary Relationship to a Relational Schema
Best Answer
Short answer : yes , add
paymentID
(PK) toPayments
table.Explanation. Even without knowing any details about your application, I'm pretty sure payment is quite important concept that has to be treated as a separate entity. Thus, it should have primary key. It's possible
payment
has a composite candidate key (say, combination of (playerID,paymentTimestamp) is very likely to be unique), but it's much easier to deal with simple primary key rather than composite.As to following requirements.
Class hierarchy doesn't match 100% table structure. There are many concepts that implemented in different ways (for instance, many-to-many relationships, inheritance). Entity identity is one of them , so your approach looks perfectly valid to me.