Docsity

Database Design: Understanding Entity-Relationship (E-R) Models, Study notes of Database Management Systems (DBMS)

Toggle sidebar
bg1
CSIS 350 โ€“ Lecture 14
Announcements
CCSC conference โ€“ student volunteers!
Midterm Grades
HW due Tuesday.
Read: Chapter 5: 119 โ€“ 135
Chapter 5
The last chapter was about designing databases from pre-existing data sources. Now we
are going to begin looking at database design for new systems.
- A data model is a plan or blueprint for a database design.
- A data model is more generalized and abstract than a database design.
- It is easier to change a data model then it is to change a database design, so it is
the appropriate place to work through conceptual database problems.
Compare this with requirements in software engineering โ€“ you don't just dive in and start
coding, first you need to understand what the client wants.
Data model allows you to understand what needs to be done before you start writing a
bunch of SQL. We're going to use some diagramming techniques to define the data
model โ€“ these diagrams are a lot easier to change than an actual database.
We're going to look at the Entity-Relationship (E-R) model. Versions:
- First developed by Peter Chen 1976
- Extended model (includes sub-types) 1986
- Information Engineering (IE) โ€“ James Martin 1990
- IDEF1X (Integrated Definition 1, extended)โ€“ National Std
- UML โ€“ targeted at OO systems
IE version is probably the simplest to understand, and is the one we will use.
Entities
An entity is something users want to track: employees, invoices, starships, students, โ€ฆ
- Entity class - a collection of entities of a given type.
- Entity instance - the occurrence of a particular entity.
See slide 1
Entity class is a collection of entities, and is described by the structure
Entity instance is the occurrence of a particular entity.
pf3
pf4
pf5

Partial preview of the text

Download Database Design: Understanding Entity-Relationship (E-R) Models and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

CSIS 350 โ€“ Lecture 14

Announcements CCSC conference โ€“ student volunteers! Midterm Grades HW due Tuesday. Read: Chapter 5: 119 โ€“ 135 Chapter 5 The last chapter was about designing databases from pre-existing data sources. Now we are going to begin looking at database design for new systems.

  • A data model is a plan or blueprint for a database design.
  • A data model is more generalized and abstract than a database design.
  • It is easier to change a data model then it is to change a database design, so it is the appropriate place to work through conceptual database problems. Compare this with requirements in software engineering โ€“ you don't just dive in and start coding, first you need to understand what the client wants. Data model allows you to understand what needs to be done before you start writing a bunch of SQL. We're going to use some diagramming techniques to define the data model โ€“ these diagrams are a lot easier to change than an actual database. We're going to look at the Entity-Relationship (E-R) model. Versions:
  • First developed by Peter Chen 1976
  • Extended model (includes sub-types) 1986
  • Information Engineering (IE) โ€“ James Martin 1990
  • IDEF1X (Integrated Definition 1, extended)โ€“ National Std
  • UML โ€“ targeted at OO systems IE version is probably the simplest to understand, and is the one we will use. Entities An entity is something users want to track: employees, invoices, starships, students, โ€ฆ
  • Entity class - a collection of entities of a given type.
  • Entity instance - the occurrence of a particular entity. See slide 1 Entity class is a collection of entities, and is described by the structure Entity instance is the occurrence of a particular entity.

Usually there are many instances of an entity class. Attributes Entities have attributes that describe their characteristics. For example, a student might have attributes such as GPA, birthdate, major, and advisor. E-R model assumes that all instances of an entity-class have the same attributes. See slide 2 and 3 Slide 2 shows original E-R style for attributes. Slide 3 shows more common style used by E-R modeling software. Identifiers

  • Identifiers are attributes that name, or identify , entity instances.
  • The identifier of an entity instance consists of one or more of the entityโ€™s attributes
  • Composite identifiers : Identifiers that consist of two or more attributes
  • Identifiers in data models become keys in database designs. o Entities have identifiers o Tables (or relations) have primary and candidate keys What is the identifier of the student entity class? How about the invoice entity class? Entities in E-R diagrams See slide 4. Depending upon the level of detail needed at a given time, we can draw entities in 3 different ways:
  • with all the attributes
  • with the identifier only
  • with no attributes The abbreviated versions are especially useful in large data models. Relationships Entities can be associated with each other through relationshships.
  • relationship classes associate entity classes
  • relationship instances associate entity instances Relationships can be given names that describe them, but this is usually not necessary.

One-to-many relationships are sometimes call parent-child relationships. The parent is the entity on the 1 side, the child is the entity on the N (many) side. These types of relationships are often called 'has-a' relationships:

  • An employee 'has-a' badge
  • An employee has a set of computers
  • An employee has a set of skills
  • A skill has a set of employees with that skill Note that sometimes the maximum cardinality has a specific value instead of a letter. For example, a sports team might have at most 15 players, or a deck of cards might have at most 52 cards. [Draw picture] Minimum cardinality: Remember, minimum cardinality is the smallest number of entities that MUST participate in a relation. Usually it is 0 or 1.
  • If 0, this means that participation in the relationship is optional
  • If 1, then at least one entity MUST participate (mandatory relationship) In E-R diagram:
  • optional relationship is indicated by a small circle on the relationship line
  • mandatory relationship is indicated by a has mark (line) across the relationship line. See slide 8. Reading minimum cardinality:
  • "Stand" on the relationship, and look toward the entity in question: o IF you see an small circle THEN that entity is optional (minimum cardinality of zero [0]). o IF you see a vertical hash mark THEN that entity is mandatory (required) (minimum cardinality of one [1]). Slide 8:
  • M-M relationship: Employee required to have a badge, badge must be assigned to an employee
  • O-O: Employee does not have to have a computer, and a computer does not have to be assigned to an employee
  • O-M: Employee must have at least one skill, but there may be skills with no employees. (Note side where the little circle is).
  • M-O: Not shown. Let's make one up. E-R Diagram Versions (Next time) Super and subtypes
  • A subtype entity is a special case of a supertype entity: o STUDENT: UNDERGRADATE or GRADUATE
  • The supertype contains all common attributes, while the subtypes contain specific attributes.
  • The supertype may have a discriminator attribute, which indicates the subtype. [See Slide 9]. Note that the most important reason to create subtypes is to avoid value-inappropriate nulls. In the example, we want to avoid null values for these attributes, which are gender- based. [Draw alternate subtype notation on board.] The super-sub type relationship is called an "is-a" relationship. A Male Patient is a Patient, and a Female Patient is a Patient.
  • Identifier of the supertype and all of its subtypes must be identical โ€“ they all represent variations of the same entity. Another Example: Employee with subtypes Hourly and Salaried. ID-Dependent entities The E-R model includes the idea of an ID-Dependent entity:
  • an entity (child) whose identifier includes the identifier of another entity (parent).
  • The ID-dependent entity is a logical extension or sub-unit of the parent: o BUILDING : APARTMENT o PAINTING : PRINT o See Slide 10.
  • The minimum cardinality from the ID-dependent entity to the parent is always one.
  • Whether the parent must have ID-dependent entities depends on the application requirements. ID-dependent entity cannot exist without its parent. Implications on DB design and processing:
  • parent record must be created before any ID-dependent child rows.
  • All child rows must be deleted if the parent row is deleted. ID-dependent entities are common:
  • Student โ€“ ClassRegistration
  • Class - ClassRegistration
  • Vehicle โ€“ Insurance
  • Others?

CSIS 350

Lecture 14: In-Class Exercise Answer these questions for the E-R diagram below. A) Classify each entity as strong, weak, supertype, subtype. B) For each numbered relationship:

  • What type is the relationship?
  • What are the maximum cardinalities?
  • What are the minimum cardinalities?
  • Give an appropriate name for the relationship. QuickTimeโ„ข and a TIFF (LZW) decompressor are needed to see this picture.