ER Diagrams
ER (entity relationship) diagrams, like UML, ODL
- Entities (Square) Ex. Lugano, Person, Robert
- Entities granularity: all entities of the same "type" form an entity set
- Attributes (Circle) Ex. for Lugano you can have population, position
- Attributes: integers, string, etc, NULL
- Attributes can be: Base(DoB) or derived(age), simple(DoB) or composite(Address) and single valued(DoB) or Multiple valued(0 or more values)
- Relationship (Diamond) Ex. Likes between Robert and Lugano
Sets and subset
-
S = {1, 2, 3, 4}
R = {1, 2}
R is a subset of S
Keys
- SUPERKEY: subset of attributes that uniquely identify an entity
- A weak superkey is a subset that is not minimal
- A primary key is a minimal subset of attributes to identify an entity (in SQL, UNIQUE)
Relationship
- R is a relationship among entity sets E1, E2, ..., En iff R is a subset of E1xE2x...xEn
- E1 = {A, B} E2 = {C, D}
E1xE2 = (A, C), (A, D), (B, C), (B, D) R = {(A, C), (B, C)}
- Example:
- Person = {Rovet, Steven}
- Computers = {Apple, Windows}
- Relationship Buys{Robert, Apple}
More on relationships
- Likes: Bob likes Alice
- Likes is a subset of cartesian product of all pairs of the form (person, person)
- Likes is an arbitrary directed graph in which person serves as the vertices and the edge are the relation
- Buys(Person, Computer, Company)
- Buys(Vendor, Product, Vendor)
- Ex. Dell buys a printer from HP
- Relationship can be one to one, many to one, one to many
- You can add an attribute to an entity when the relationship is one to one. Many to one you can go to the many
Strong VS Weak Entities
- A strong entity set is a set of elements that can be identified entirely by their attributes
- A weak entity set can not be identify by their attributes
Discriminant
- An attribute becomes the discriminant when a weak entity needs that attribute to be identify by a strong entity
- The thick line represent the path to identify a weak entity from a strong entity
ISA
- ISA means "it's a" relation
- Different types of ISA relations
- disjoint: no entity can be in more than one subclass
- overlapping: an entity can be in more than one subclass
- total: every entity has to be in a subclass
- partial: an entity does not have to be in a subclass
- Instead of ISA you can put the first letter (Ex:O, P for overlapping and partial)
Cardinality Constrains
The numbers on the connections represents the cardinality in the relation.