primary/foreign keys in uml
uml
Solution
First off: why do you want to draw it in UML? If you already have an ERD, what additional/alternate property do you want to illustrate with a UML class diagram that the ERD doesn't give you?
Why? Because UML is a tool. On the assumption the diagram is for human consumption only (i.e. you're not code generating from it) then you should use UML to expose the information you're trying to communicate.
As a general standard UML says nothing about how you formalise identity (PK/FK). UML follows the OO idiom that every object has implicit identity - therefore you don't need to specify it explicitly. So in the simplest case, you could:
- list PK attributes as normal attributes;
- ignore FK attributes altogether.
If that meets your modelling needs then you're done.
As a second refinement, you could tag the PK attributes with an ocl `isUnique()` constraint, again ignoring the FKs.
Another option would be to use the rules of Executable UML. It denotes both PKs ('Identifiers'} and FKs ('referential attributes'} directly on the class diagram. So it's closest to capturing everything in the ERD.
So in summary: there is no UML-imposed right answer. It all depends on what you want to communicate with the diagram.
Problem
I am doing a UML model based on my ERD generated with MySQL workbench. But now i have a doubt about the primary and foreign keys representation in a class diagram. In the traditional UML diagram we should include the primary keys as atributes of each class? For example, the `id_user` or the `id_list` ? And about the foreign keys ? These ones are ignored as attribute but reflected as associations? thanks