Presentation is loading. Please wait.

Presentation is loading. Please wait.

ER Data Models Ctd. CSET 3300.

Similar presentations


Presentation on theme: "ER Data Models Ctd. CSET 3300."— Presentation transcript:

1 ER Data Models Ctd. CSET 3300

2 ER Diagram - Example Consider a database that records the grades of students in different exams of different course offerings. assume that course offerings include time, room; and can be identified uniquely by course_no, semester, year, section_no. students, including student-id, name, and program; exam, including eid (optional), name, place, time. Furthermore, grades of students in different exams of course offerings must be appropriately modeled. Construct an E-R diagram that models exams as entities, and uses a ternary relationship, for the above database.

3 ER Diagram with Ternary Relationship
semester sid name course_no time student takes course-offerings room grade year section_no program exam eid time name place

4 Subclasses Subclass = special case = fewer entities = more properties.
Example: Ales are a kind of beer. Not every beer is an ale, but some are. Let us suppose that in addition to all the properties (attributes and relationships) of beers, ales also have the attribute color.

5 Subclasses in E/R Diagrams
Assume subclasses form a tree. I.e., no multiple inheritance. Is_a triangles indicate the subclass relationship. Point to the superclass. NOTE:Every isa relationship is one-one NOTE:But we don’t draw 2 arrows manufacturer Beers name isa Ales color

6 Another Example length Movies title isa isa MovieStars Murder-
year isa isa MovieStars Murder- Mysteries cartoons weapon Voices

7 Keys A key is a set of attributes for one entity set such that no two entities in this set agree on all the attributes of the key. It is allowed for two entities to agree on some, but not all, of the key attributes. We must designate a key for every entity set.

8 Keys in E/R Diagrams Underline the key attribute(s). Beers name
manufacturer

9 Keys in is_a Relationship
In an Is_a hierarchy, only the root entity set has a key, and it must serve as the key for all entities in the hierarchy. Beers name manufacturer Is_a Ales color

10 Example: a Multi-attribute Key
dept number hours room Courses Entity can have more than one key. Note that hours and room could also serve as a key, but we must select only one key.

11 Weak Entity Sets Occasionally, entities of an entity set need “help” to identify them uniquely. Entity set E is said to be weak if in order to identify entities of E uniquely, we need to follow one or more many-one relationships from E and include the key of the related entities from the connected entity sets.

12 Example name is almost a key for football players, but there might be two with the same name. number is certainly not a key, since players on two teams could have the same number. But number, together with the Team related to the player by Plays-on should be unique.

13 In E/R Diagrams name number name Plays- on Players Teams
Double diamond for supporting many-one relationship. Double rectangle for the weak entity set. A weak entity can be identified uniquely only by considering the primary key of another (owner) entity Owner entity set and weak entity set must participate in one-to-many relationships (one owner, many weak entities). Weak entity set must have total participation in this identifying relationship set.

14 Example: Course Offering
course offerings includes course number, year, semester, section number, instructor(s), timings, and classroom semester course_no time is offered course- offerings course room year section_no

15 Weak Entity-Set Rules A weak entity set has one or more many-one relationships to other (supporting) entity sets. Not every many-one relationship from a weak entity set need be supporting. The key for a weak entity set is its own underlined attributes and the keys for the supporting entity sets. E.g., player-number and team-name is a key for Players in the player-team example.

16 Identifying a Weak Entity Type
A Weak entity type doesn’t have a primary key. If X is a weak entity type and Y is the entity type on which X is dependent. We form a primary key for X by combining the primary key of Y which one or more attributes, called discriminator or partial key, from X. In an E/R Diagram, a partial key is usually dash-underlined. e.g., primary key for DEPENDENT: {Employee No., DName}.

17 Example: Employee-Dependent
Address Name

18 Notations – A Summary Name Name isa

19 Design Techniques Avoid redundancy.
Don’t use an entity set when an attribute will do. Limit the use of weak entity sets.

20 Avoiding Redundancy Redundancy occurs when we say the same thing in two different ways. Redundancy wastes space and (more importantly) encourages inconsistency. The two instances of the same fact may become inconsistent if we change one and forget to change the other, related version.

21 Example: Good name name addr ManfBy Beers Manfs
This design gives the address of each manufacturer exactly once.

22 Example: Bad name name addr ManfBy Beers Manfs manf
This design states the manufacturer of a beer twice: as an attribute and as a related entity.

23 Example: Bad name manf manfAddr Beers
This design repeats the manufacturer’s address once for each beer; loses the address if there are temporarily no beers for a manufacturer.

24 Entity Sets Versus Attributes
An entity set should satisfy at least one of the following conditions: It is more than the name of something; it has at least one nonkey attribute. or It is the “many” in a many-one or many-many relationship.

25 Example: Good name name addr ManfBy Beers Manfs
Manfs deserves to be an entity set because of the nonkey attribute addr. Beers deserves to be an entity set because it is the “many” of the many-one relationship ManfBy.

26 Example: Good name manf Beers
There is no need to make the manufacturer an entity set, because we record nothing about manufacturers besides their name.

27 Example: Bad name name ManfBy Beers Manfs
Since the manufacturer is nothing but a name, and is not at the “many” end of any relationship, it should not be an entity set.

28 Don’t Overuse Weak Entity Sets
Beginning database designers often doubt that anything could be a key by itself. They make all entity sets weak, supported by all other entity sets to which they are linked. In reality, we usually create unique ID’s for entity sets. Examples include social-security numbers, automobile VIN’s etc.

29 When Do We Need Weak Entity Sets?
The usual reason is that there is no global authority capable of creating unique ID’s. Example: it is unlikely that there could be an agreement to assign unique player numbers across all football teams in the world.

30 Example: University DB
The university keeps track of each student's name, student number, social security number, current address and phone number, birthdate, sex, class (freshman, graduate), major department, minor department (if any), degree program (B.A., B.S., ... Ph.D.).  Some user applications need to refer to the city, state, and zip code of the student's current address and to the student's last name.  Both social security number and student number are unique for each student. All students will have at least a major department.

31 Example: University DB (cont.)
Each department is described by a name, department code, office number, and college.  Both the name and code have unique values for each department. Each course has a course name, description, course number, number of credits, and offering department.  The course number is unique for each course.

32 Example: University DB (cont.)
Each section has an instructor, semester, year, course, and section number.  The section number distinguishes sections of the same course that are taught during the same semester/year; its value is an integer (1, 2, 3, ... up to the number of sections taught during each semester).

33 Example: University DB (cont.)
A grade report must be generated for each student that lists the section, letter grade, and numeric grade (0,1,2,3, or 4) for each student and calculates his or her average GPA.

34 ER Diagram for University DB
Student Class StudentID SSN Sex Zip Degree City Birth date State Name Address Department DName DCode OfficeNumber OfficePhone College Course CName CourseDesc CNumber Credits Section Instructor Year Semester SectionNumber GPA Numeric Grade Letter Grade Grade_Report Belong_To Offer Minor In Major In


Download ppt "ER Data Models Ctd. CSET 3300."

Similar presentations


Ads by Google