Exam 2010 1B

70 views
Skip to first unread message

Robert Silverflod

unread,
Mar 10, 2014, 4:12:55 PM3/10/14
to tda357...@googlegroups.com
I have  a question regarding the construction of a ER diagram from a schema.
How do a know (from the schema perspective) when there should be many to many or many to one?
As in the question Link -> User, and Entry -> User.
 

Niklas Broberg

unread,
Mar 11, 2014, 4:35:15 AM3/11/14
to Robert Silverflod, tda357...@googlegroups.com
Your first question for any relation should be, does this relation represent a relationship or an (possibly weak) entity? Here is a non-comprehensive list of things to consider:

1. If a relation has fewer than two references, it cannot represent a relationship, since a relation from a relationship always references both (or all) its related entities.
2. If a relation has a key where not all the attributes included in that key reference other relations, then it cannot represent a relationship. All forms of relationships that translate into relations have as key either the combination of the keys of the related entities (many-to-many), or the key of one of the related entities (the "many" side in a many-to-at-most-one).
3. If a relation has a composite key where its parts reference two (or more) other relations, and all of its parts are included in one such reference, it represents a relationship. An entity must either have a key that has at least some part of it not referencing a different relation, or its key must in entirety reference a single other relation (in the case of a sub-entity). 
4. If a relation has a composite key where part of it references another relation and part of it does not, it represents a weak entity (or in special cases a multi-valued attribute - let's not go there).

5. If a relation representing a relationship has a key that is a composite of all its references, it represents a many-to-many relationship.
6. If a relation representing a relationship has a key that consists of only one of its references, it represents a many-to-at-most-one relationship.

7. If a relation *representing an entity* has an attribute that references another relation, that attribute and reference represent a X-to-one relationship that has been translated away as part of the "X" side. If the attribute in question is part of the key, the relationship was a supporting relationship (see 3). Note that it could represent both a many-to-exactly-one relationship, or a many-to-at-most-one relationship that has been translated using a "nulls" approach.
7b. Note that ISA relationships fall into this category. If the relationship is an ISA, the key of this relation is the same as the reference.


Looking at 2010 1B:
* Users, Links, Entries, Images and Blurbs all represent entities, since they have fewer than two references (see 1).
* Friends represents a relationship (see 3 and 5).
* Comments could be either a sub-entity (see 3) or a many-to-at-most-one relationship (see 6). In fact, those two solutions are equivalent - but conceptually a comment deserves to be an entity.
* Images and Blurbs also represent sub-entities (see 3 and 7b).
* Links represents a weak entity (see 4).

Now the answer to your question follows from 7: The two references you mention both exist on relations that represent entities, then those two references cannot represent many-to-many relationships. 

HTH, Niklas

--
You received this message because you are subscribed to the Google Groups "tda357-vt2014" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tda357-vt201...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages