CS 325 - Week 6 Lecture 1 - 2016-09-27

*   TO our relationship lines
    (the basic ones, with diamonds on them --
    SUPERTYPE/SUBTYPE relationship lines
    are DIFFERENT...)

   ...we need to ADD maximum and minimum
   cardinalities;

*   maximum cardinalities
    *   express the number of entity instances
        of one entity class
        to which another entity class's entity
	instances CAN be related, at the MOST

    *   you have to look at this in BOTH
        "directions" ---

        _____            _____
        | A |-----<>-----| B |
        -----    cooks   -----
               
 
        *   in the cooks relationship,
	    for AN instance of A,
	    at MOST how many instances of B
	    CAN it be related to?

        *   in the cooks relationship,
	    for AN instance of B,
	    at MOST how many instances of A
	    CAN it be related to?

    *   interestingly, this boils down to only 3 or 4
        different possibilities, in practice:

	*   1:1 - read as "one to one"
	    *   an entity instance in A is related to
	        AT MOST one entity instance in B,
		and an entity instance in B is related to
		AT MOST one entity instance in A

        *   1:N - read as "one to en" or "one to many"
            (can write as 1:M, or N:1, or M:1,
	    although some write N:1 as a 4th option)
            *   an entity instance in A CAN be related
	        to more than one entity instance in B,
		BUT!! an entity instance in B can be
		related to AT MOST 1 entity instance in A

        *   N:M - read as "en to em" or "many to many"
	    (can be written as M:N, also)
            *   an entity instance in A CAN be related
	        to MULTIPLE entity instances in B,
		and an entity instance in B CAN be related
	        to MULTIPLE entity instances in A

    *   HOW do you show in an ERD?

        ...turns out, in DIFFERENT ways in different
	textbooks and different software!

	...THIS is how you are REQUIRED to do so
	for CS 325:

        *   we will put a 1 or N or M
	    near the relationship line
	    near the entity class rectangle
	    near EACH entity class rectangle

        _____ 1        N _____
        | A |-----<>-----| B |
        -----    cooks   -----

        *   IF, in this world, an instance of A *CAN*
	    cook multiple instances of B,
	    BUT an instance of B can be cooked by
	    at MOST one instance of A,
	    you'd place the 1 and N as shown above

    *   remember: this determination of WHICH is
        "right" should be based ON THE SCENARIO,
	on the business rules in that scenario!

*   that's MAXIMUM cardinality -- how many CAN
    be related;

    MINIMUM cardinality is how many MUST
    be related (if any);

    in MAXIMUM cardinality, we tend to
    care about one or many;

    in MININUM cardinality, we tend to
    care about NONE or ONE
    ...does an entity instance in A
    HAVE to be related to at least one
    entity instance in B,
    and vice versa?

        *   we will put a 0 or 1 
	    (or, if you prefer, an oval or hash)
	    ON the relationship line
	    near the entity class rectangle
	    near EACH entity class rectangle
    
        ___________ 1         N ______________
        | stylist |-|---<>----O-| style appt |
        -----------    styles   --------------

        ...the above attempts to say that a
        stylist does not HAVE to have an style
	appointments -- BUT a style appointment
	MUST have a stylist