23
MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation © Akhilesh Bajaj, 2008. All Rights Reserv

MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Embed Size (px)

Citation preview

Page 1: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

MIS 7003

MIS Core Course

The MBA Program

The University of Tulsa

Professor: Akhilesh Bajaj

Introduction to Database Design

All Slides in this presentation © Akhilesh Bajaj, 2008. All Rights Reserved.

Page 2: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

What is a Data Model?

• A way to structure information fields in the business

• We want to make sure the same information is not repeated for data entry

• In a business information system, there is data entry (WRITE) and data querying (reports), also termed READ.

• While many people can reuse information once it is entered, in reports, (i.e. many READS), we don’t really want duplicate/redundant data entry

Why?

• A data model at the design level allows us to structure the fields so they are entered only once during data entry. This eliminates duplicate work and removes potential for error.

• We don’t design reports when we develop a data model schema; instead, we onlycare about the data entry part.

• We will learn a method to structure our fields: Entity Relationship Diagramming.

Page 3: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Entities & Entity Sets

• An entity is a “thing” or “object” in the real world that is distinguishable from other objects.

• An entity set (or entity class) is a set of things or objects that are described by the same properties. E.g., Joe Dahmer is a person. “Persons” is an entity classdescribed by, say, name, address, height, weight, fingerprint, age and gender. Hence, Joe Dahmer, who is an element of the entity set “persons” is described by these properties.

• In the example above, Joe Dahmer is the entity and “persons” is the entity class or entity set.

• Consider 2 entity sets, “employees” and “persons”. “Employees” may be described by additional properties, such as salary and grade. Joe Dahmer could be a member ofboth sets.

Page 4: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Attributes

• An attribute is a descriptive property possessed by each element (or entity) in an entity set.

E.g., the entity set “persons” in the previous slide has seven attributes.

• Each attribute is associated with a domain. E.g., name is associated with the character string domain. fingerprint is associated with the JPEG domain.

• The domain is the set of permitted values of the attribute.

• The domain is similar to type in programming languages, and the attribute is similar to a variable of that type.

Page 5: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Types of Attributes

Single-Valued and Multivalued Attributes• Some attributes, such as height, are single valued, i.e., they have only one value at a time.

• Other attributes, such as dependent_name, may be multivalued, i.e., they can have multiple values at the same time (in this case, if there is > 1 dependent for a person).

Page 6: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Relationships and Relationship Sets

• A relationship is an association among two or moreentities. E.g., Akhilesh (entity) teaches (relationship) MIS7003_fall_2005_sectionA (entity).

• A relationship set is a set of relationships of the same type.E.g., Professors (entity set) teach (relationship set) course_sections (entity set).

• Relationship sets relate entity sets in meaningful, real world relationships.

• Each entity set involved in a relationship set plays a role in that relationship set. E.g., Professors play the role of teachers in the teach relationship set. Course_sections play the role of taught by in the teach relationship set.

Page 7: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Attributes of Relationship Sets

• An attribute of a relationship set is very similar to an attribute of an entity set. Attributes of relationshipsets are used when we are trying to capture additional information about the relationship set. E.g., the teach relationship set may have the attributesdate_began, date_ended. These 2 relationship set attributesof the teach relationship set tell us the beginning and ending dates that the course_section was taught. Each relationship in the relationship set will have values for the relationship set attributes. So, the relationship Akhilesh teaches MIS7003_fall_2009_sectionA will have the values ‘August 20, 2009’ and ‘Dec 3, 2009’ for the date_began and date_ended attributes.

Page 8: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

• Several software are available for drawing ER diagrams. Each one uses a slightly different convention.

• We shall use a convention that covers more than almost all conventions, and is as follows:

Drawing ER diagrams

Entity SetAttribute (underlinedif a primary key)

Relationship Set

Page 9: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Is it a real-world object?

• Is it likely to be in relationships with other objects?

• Is it described by a set of properties?Then Entity set•Is it just an attribute of an object? Then attribute• Is it a set of arcs or links between objects in two boxes? Then relationship set

Examples 1. Should telephone be a telephone_number attributeor an entity set Telephones, described by telephone_number (and maybe other attributes like phone_type)?2. Should sale between employee and customer be a relationship or a separate entity set with diamonds (relationship sets) going to customer and employee?

Design Issues: Entity Sets or Attributes or Relationship??

Page 10: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Very Important Facts

-We never ever ,ever repeat anything in the ER diagram.

-If we identify a “bunch of objects” each described by the same set of properties (or attributes) then it’s most likely an entity set

-If it’s an entity set it will have a primary key.

-If it’s a relationship set it will not have its own primary key. It may have some attributes, but it’s really just a “bunch of links” between objects in boxes (entity sets).

Page 11: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Existence Dependencies

• If the existence of entity x depends on entity y, then if y is deleted, x should also be deleted. E.g., the entity set course_sections is existence dependent on theentity set courses. So, each course_section is dependent on one andonly one course for its existence.

Thus, this section Fall2009A is existence dependent on the course MIS7003 (if that is how a course is defined). The course can have many sections

• Other examples of existence dependencies?

• In the above example, we say that course_sections is the weak entity set, while courses is the corresponding strong entity

set. Another way to think: If we talk about the weak entity, we always HAVE to refer to the strong entity. If we say section Fall2009A, the question is: which course are we talking about?

In a bank, if we say transaction id3, the question is: which account?

Page 12: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Rule for Determining if a Weak Entity Set is Appropriate

We cannot identify the objects in the weak box without the primary key of the strong box.

Page 13: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Existence Dependencies

• The relationship set between a weak entity set and the corresponding strong entity set is shown differently in an ERdiagram.

• The weak entity set is shown thus:

Strong entity set Relationship setshowing existence dependency

Weak entity set

Double Diamond ShowsExistence Dependency

Page 14: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

• An entity set may contain subgroupings of entities that are distinct in some way from other entities in the same set. E.g., The entity set persons contains a subgrouping of personswho are employees. Students may contain undergraduate_students and graduate_students.

• Subgroupings may be different from the other entities in the setin the sense that they have additional attributes (e.g., graduate_students have an undergraduate_major) or they may be involved in relationships that other entities in the same set are not (e.g., employees participate in the relationship set works_for with the entity set departments). Rule of thumb: At least 2 extra attributes and/or relationships to create a subclass

Subclass / Superclass Hierarchies

Page 15: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

• What are some other examples of this?

• We say that the superset is the entity superclass, while the subset is the entity subclass.

• Subclasses inherit all the attributes of their superclass and alsoparticipate in all the relationship sets that the superclass participates in. E.g., employees is a subclass of persons. It inherits all the attributes of persons. It participates in all the relationship setsthat persons participates in. In addition, it may have some extra attributes, and/or mayparticipate in some extra relationship sets.

Subclass / Superclass Hierarchies

Page 16: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Representation of Subclasses and Superclasses

Subclass / Superclass Hierarchies

Superclass

IS A

SubclassSubclass --------

•In this course, a subclass can have one and only one superclass• A superclass can have one or more subclasses. • Note the inverted triangle: the base is towards the superclass.

attribute

attribute

Page 17: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Summary of Data Abstraction Patterns

Entity set: Bunch of objects, each object described by same set of attributes

Multivalued attribute: multiple values at same time for an object in a box

Relationship Set: Bunch of arcs or links between objects so that an object is at eachend of the link. Identified by primary keys of end points.

Weak Entity Set: Needs primary key of another box as well as its own in order to be uniquely identified.

Subclass: Extra attributes / relationships of some of the objects in a box are modeled as a separate box so that these objects co-exist in both boxes. Inherits primary key of superclass.

Page 18: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

ER Model Example

University Schema:

Objects: Courses, Course sections, Professors, Students (graduate and undergraduate), Classrooms, buildings

Example course numbers: MIS7003, MIS4233, MIS3023. Example course section identifiers: MIS7003Fall2008A, MIS4233Fall2008AExample StudentID: 0918512Example FacultyID: 0918452Example BuildingID: HELM, OLIPExample classroom ID: HELM316

Events: A student takes a course section and gets a grade, a professor teaches a course section and gets a rating for that course section, a graduate student may TA a Course section, and also get a rating for it.

Example grade: ‘A’Example Professor rating: “Excellent’Example GA rating: ‘Excellent’

Let us build an ER schema for this description.

Page 19: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

In Class Assignment 1

Al’s motor shop (AMS) is an automobile repair facility owned by the Capone family. AMS has 5 repair bays. Each repair bay (place where car is repaired) has a bay_id and bay_location. AMS employs 14 employees. Each employee has an employee_id, address, phone and salary. Of these 14, 2 are office staff. They are further described by typing_speed and degree_held. The 12 mechanics are further described by tech_level. Each mechanic is assigned to work on one bay. AMS customers have a cust_id, name, address, phone. In addition, Mr. Capone also wants to capture information for each customer that lists the mechanic who last did a job for the customer, the date on which the job was done, and the amount the customer paid to AMS.

• Please capture the above requirements in a DSD diagram.

Page 20: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation
Page 21: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

In Class Assignment 2

Wimpy runs a burger joint. He has 6 employees working for him. Some of these are shift managers, the others are grade 1 workers. Wimpy wants you to capture information on each shift. A shift is 8 hours long. Each shift needs a shift manager and 0 or moregrade 1 workers. Being a purist, Wimpy sells only burgers, and only 3 types of burgers at that: the wimpy mini, the wimpy burgerand the wimpy super. Each burger type has a price, a recipe andamount of fat calories. In each shift, burgers of all 3 types can be sold. Each shift has a time began and a time ended. Wimpy wants to capture information on how many burgers were sold (of each type) in a shift.

• Please capture the above requirements in a DSD diagram.

Page 22: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation
Page 23: MIS 7003 MIS Core Course The MBA Program The University of Tulsa Professor: Akhilesh Bajaj Introduction to Database Design All Slides in this presentation

Tables Construction & Foreign KeysEmployees (emp_id, phone, address, salary)

Mechanics (emp_id, tech_level) emp_id FK REF employees

Office_staff (emp_id, typing_speed, degree_held)emp_id FK REF employees

Repair_bays (bay_id, bay_loc)Customers (cust_id, name, address, phone)

Last_job (cust_id, emp_id, date, payment) cust_id FK REF customers, emp_id FK refs mechanics

Works (emp_id, bay_id) emp_id FK REF mechanics, bay_id FK REF repair_bays

Tables are different from screens but can be mapped from them.They contain the data at the “back end”. Screens are the “front end”.