One compound key is made by two Ids of two classes. In my use cases, one of Ids may not present to the entity with the compound key. Can a compound key allow one element be null? I can't find related documents online.
Asked
Active
Viewed 630 times
1 Answers
0
I think this one has already been answered: here. In general, it's a bad idea for primary keys to be null (and generally databases don't let you have null PKs).
-
My question is about one of elements in a compound key is null, but not all of them. In the other words, the compound key won't be null, but one element may be null. – vic Feb 09 '14 at 06:11
-
The background of my question is about denormalization of an one-to-many relation. I have an one-to-many relation in our system. I need to create a mirror entity by flatting the one-to-many relation. I have a compound key, which is made up with the ids of the two entities in the one-to-many relation, in the mirrored entity. – vic Feb 09 '14 at 06:18
-
Just to make sure I understand you, you're saying you have two tables (A and B), and you want to make an entity that represents both of these tables, using their PKs as a composite key? – John Feb 09 '14 at 06:39
-
In that case, why can't you use the PK of the table in the "many" part of the relationship? Since it's one-to-many instead of many-to-many, that PK will still be unique, and you won't need to worry about maintaining a composite key. – John Feb 09 '14 at 20:02
-
That can be done in the way. I am considering from a query point of view. Most of queries will take the parent ID, but not the children IDs. – vic Feb 09 '14 at 20:48