CS 405G Introduction to Database Systems Lecture 3: ER Model Instructor: Chen Qian.

Slides:



Advertisements
Similar presentations
Database Design The process of finding user requirement
Advertisements

Constraints in Entity-Relationship Models Zaki Malik September 18, 2008.
Conceptual Data Modeling: ER
Chapter 31 Chapter 3 Data Modeling Using the Entity-Relationship Model.
Ch5: ER Diagrams - Part 1 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
DATABASE APPLICATION DEVELOPMENT SAK 3408 Database Design II (week 3)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 3- 1.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Week 3 Outline Overview of Database Design Process Example Database Application (COMPANY) ER Model.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – ER Model.
CS411 Database Systems Kazuhiro Minami
CS 405G Introduction to Database Systems
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas.
Data Modeling Using the Entity-Relationship Model
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Data Modeling Using the Entity-Relationship (ER) Model CS 340: Introduction to Databases.
CSE314 Database Systems Data Modeling Using the Entity- Relationship (ER) Model Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model.
the Entity-Relationship Model
Outline What is ER Model? And Why? Example COMPANY Database
Entity-Relationship Model. 2 Outline  What is ER Model? And Why?  Overview of Database Design Process  Example COMPANY Database  ER Model Concepts.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Data Modeling Using the Entity-Relationship (ER) Model
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Data Modeling Using the Entity-Relationship
Lecture On Database Analysis and Design By- Jesmin Akhter Lecturer, IIT, Jahangirnagar University.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
ER Data Models Ctd. CSET 3300.
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Data Modeling Using the Entity- Relationship (ER) Model.
Initial Design of Entity Types for the COMPANY Database Schema Based on the requirements, we can identify four initial entity types in the COMPANY database:
CS 405G: Introduction to Database Systems Lecture 2 : Database Design I.
1 Session 2 Welcome: The fifth learning sequence “ Entity-Relationship Model -2“ E-R Model Recap : In the previous learning sequence, we discussed the.
Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Tallahassee, Florida, 2015 COP4710 Database Systems E-R Model Fall 2015.
Entity-Relationship Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Conceptual Modeling and Database Design.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Data Modeling Using the Entity-Relationship (ER) Data Model (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 3- 1.
Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces.
Database Systems – ER Diagrams EXAMPLE COMPANY DATABASE Requirements of the Company (oversimplified to illustrate) The company is organized into DEPARTMENTs.
Chapter 2 Data Modeling Using the Entity-Relationship (ER) Model Copyright © 2004 Pearson Education, Inc.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 3 Data Modeling Using Entity-Relationship Model.
Data Modeling Using the Entity-Relationship (ER) Data Model.
Data Modeling Using the Entity- Relationship (ER) Model.
Chapter 3: Data Modeling Using the Entity-Relationship (ER) Data Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
CSE 412/598 DATABASE MANAGEMENT COURSE NOTES 3. ENTITY-RELATIONSHIP CONCEPTUAL MODELING Department of Computer Science & Engineering Arizona State University.
Database Management COP4540, SCS, FIU Database Modeling Using the Entity- Relationship Model (Continued)
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Example COMPANY Database
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Lecture # 16 July 26,2012 Data Modeling using the Entity Relationship.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Lecture # 17 July 28,2012 Data Modeling using the Entity Relationship.
Introduction to Database Systems, CS420
CS4222 Principles of Database System
Data Modeling Using the Entity- Relationship (ER) Model
Database Management Systems
COP4710 Database Systems E-R Model.
Constraints in Entity-Relationship Models
Initial Design of Entity Types: EMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT Gender.
CS 405G: Introduction to Database Systems
Presentation transcript:

CS 405G Introduction to Database Systems Lecture 3: ER Model Instructor: Chen Qian

6/11/20162 Review A database is a large collection of integrated data A miniworld is some aspect of the real word, described by facts (data) A data model is a group of concepts for describing data. Which one(s) is a data model ER model Relation model Objected oriented programming model Chen Qian Univ. of Kentucky

6/11/20163 Today’s Outline Database design ER Model ER Diagrams – Notation Database schema Case studies Chen Qian Univ. of Kentucky

6/11/20164 Database Design Requirement Analysis: Understand the mini-world being modeled Conceptual Database Design: Specify it using a database design model A few popular ones are: Entity/Relationship (E/R) model (in this course) UML (Unified Modeling Language) Intuitive and convenient Logical Design: Translate specification to the data model of DBMS Relational, XML, object-oriented, etc. Chen Qian Univ. of Kentucky

6/11/20165 Database Design Chen Qian Univ. of Kentucky

6/11/20166 An Database Design Example The company is organized into DEPARTMENTs. Each department has a name, number and an employee who manages the department. We keep track of the start date of the department manager. Each department controls a number of PROJECTs. Each project has a name, number and is located at a single location. We store each EMPLOYEE’s social security number, address, salary, sex, and birthdate. Each employee works for one department but may work on several projects. We keep track of the number of hours per week that an employee currently works on each project. We also keep track of the direct supervisor of each employee. Each employee may have a number of DEPENDENTs. For each dependent, we keep track of their name, sex, birthdate, and relationship to employee. Chen Qian Univ. of Kentucky

6/11/2016Luke Huan Univ. of Kansas7

6/11/20168 Entity-relationship (E/R) model Historically and still very popular Can think of as a “watered-down” object-oriented design model Primarily a design model—not directly implemented by DBMS Designs represented by E/R diagrams there are other styles Chen Qian Univ. of Kentucky

6/11/20169 Entities and Attributes Entity: A specific object or “thing” in the mini-world that is represented in the database. For example, the EMPLOYEE John Smith, the Research DEPARTMENT, the iPhone8 PROJECT. Attributes : properties used to describe an entity. For example, an EMPLOYEE entity may have a Name, SSN, Address, Sex, BirthDate A specific entity will have a value for each of its attributes. For example, a specific employee entity may have Name='John Smith', SSN=' ', Address ='731 Fondren, Houston, TX', Sex='M', BirthDate='09-JAN-55' Chen Qian Univ. of Kentucky

6/11/ Types of Attributes Simple vs. Composite Attributes Simple: Each entity has a single atomic value for the attribute. For example, SSN or Sex. Composite: The attribute may be composed of several components. For example, Name (FirstName, MiddleName, LastName). Chen Qian Univ. of Kentucky

6/11/ Types of Attributes (cont.) Single-valued vs. Multi-valued. Single-valued: an entity may have at most one value for the attribute Multi-valued: An entity may have multiple values for that attribute. For example, PreviousDegrees of a STUDENT. {PreviousDegrees}. NULL values What if the student does not hold a previous degree? What if the student has a previous degree but the information is not provided? Apartment number in an address Chen Qian Univ. of Kentucky

6/11/ Types of Attributes (cont.) Stored vs. derived Number of credit hours a student took in a semester GPA of a student in a semester Chen Qian Univ. of Kentucky

6/11/ Key Attributes Entities with the same basic attributes are grouped or typed into an entity type (or entity set). For example, the EMPLOYEE entity type or the PROJECT entity type. An attribute of an entity type for which each entity must have a unique value is called a key attribute (or key, in short) of the entity type. For example, SSN of EMPLOYEE. A key attribute may be composite. An entity type may have more than one key. Chen Qian Univ. of Kentucky

6/11/ SUMMARY OF ER-DIAGRAM NOTATION Meaning ENTITY TYPE ATTRIBUTE KEY ATTRIBUTE MULTIVALUED ATTRIBUTE COMPOSITE ATTRIBUTE DERIVED ATTRIBUTE Symbol Chen Qian Univ. of Kentucky

6/11/ Summary (cont.) Chen Qian Univ. of Kentucky

6/11/ Summary (cont.) Chen Qian Univ. of Kentucky John Smith is an entity. EMPLOYEE is an entity type. SSN is a key attribute. The SSN of John, , is a value of the attribute

6/11/ Relationships A relationship relates two or more distinct entities with a specific meaning. For example, EMPLOYEE John Smith works on the iPhone8 PROJECT or EMPLOYEE Franklin Wong manages the Research DEPARTMENT. Relationships of the same type are grouped or typed into a relationship type (or relationship set). For example, the WORKS_ON relationship type in which EMPLOYEEs and PROJECTs participate, or the MANAGES relationship type in which EMPLOYEEs and DEPARTMENTs participate. Chen Qian Univ. of Kentucky

6/11/ Relationships The degree of a relationship type is the number of participating entity types. Both MANAGES and WORKS_ON are binary relationships. Name a 3-degree relationship? John works on the iPhone8 project since Chen Qian Univ. of Kentucky

6/11/ Instances of a relationship: a set of relationships e 1 e 2 e 3 e 4 e 5 e 6 e 7 EMPLOYEEWORKS_FOR d 1 d 2 d 3 DEPARTMENT Chen Qian Univ. of Kentucky r1r2r3r4r5r6r7r1r2r3r4r5r6r7

6/11/ Summary Chen Qian Univ. of Kentucky John Smith work on the iPhone8 project is a relationship. WORKS_ON is an relationship type. The set of WORKS_ON relationships of all current employees and departments is an instance of WORKS_ON

6/11/ Key constraints One-to-one (1:1) MANAGE One-to-many (1:N) or Many-to-one (N:1) DEPENDENT_OF Many-to-many WORKS_ON Chen Qian Univ. of Kentucky

6/11/ Many-to-one (N:1) RELATIONSHIP e 1 e 2 e 3 e 4 e 5 e 6 e 7 EMPLOYEE r1r2r3r4r5r6r7r1r2r3r4r5r6r7 WORKS_FOR d 1 d 2 d 3 DEPARTMENT Chen Qian Univ. of Kentucky

6/11/ Many-to-many (M:N) RELATIONSHIP e 1 e 2 e 3 e 4 e 5 e 6 e 7 r1r2r3r4r5r6r7r1r2r3r4r5r6r7 p 1 p 2 p 3 r8r8 r9r9 Chen Qian Univ. of Kentucky EMPLOYEEWORKS_ONPROJECT

6/11/ More Examples Each student may have exactly one account. Each faculty may teach many courses Each student may enroll many courses Students Enroll Courses TaughtBy InstructorsStudents Own UK Accounts Chen Qian Univ. of Kentucky

6/11/ The (min,max) notation relationship constraints (1,1) (0,1) (1,N) (1,1) Chen Qian Univ. of Kentucky

6/11/ Participation constraints total participation All entities of an entity type participate in the relationship type. Example: The participation of EMPLOYEE in WORKS_IN. partial participation A participation that is not total Example: The participation of EMPLOYEE in MANAGE. Chen Qian Univ. of Kentucky

6/11/ The (min,max) notation relationship constraints (1,1) (0,1) (1,N) (1,1) Chen Qian Univ. of Kentucky

6/11/ Recursive relationship We can also have a recursive relationship type. Both participations are same entity type in different roles. For example, SUPERVISION relationships between EMPLOYEE (in role of supervisor or boss) and (another) EMPLOYEE (in role of subordinate or worker). In ER diagram, need to display role names to distinguish participations. Chen Qian Univ. of Kentucky

6/11/ A RECURSIVE RELATIONSHIP SUPERVISION e 1 e 2 e 3 e 4 e 5 e 6 e 7 EMPLOYEE r1r2r3r4r5r6r1r2r3r4r5r6 SUPERVISION Chen Qian Univ. of Kentucky

6/11/ Weak Entity Types A week entity is an entity that does not have a key attribute A weak entity must participate in an identifying relationship type with an owner Entities are identified by the combination of: A partial key of the weak entity type The particular owner they are related to in the owner type Chen Qian Univ. of Kentucky

6/11/2016Luke Huan Univ. of Kansas31

6/11/ Weak Entity Types Example: Suppose that a DEPENDENT entity is identified by the dependent’s first name and birthdate, and the specific EMPLOYEE that the dependent is related to. DEPENDENT is a weak entity type with EMPLOYEE as its owner via the identifying relationship type DEPENDENT_OF An dependent of John Smith, Mary, is identified by her first name Mary, birthdate 1/1/1980, and the entity John. Chen Qian Univ. of Kentucky

6/11/ SUMMARY OF ER-DIAGRAM NOTATION FOR ER SCHEMAS Meaning ENTITY TYPE WEAK ENTITY TYPE RELATIONSHIP TYPE IDENTIFYING RELATIONSHIP TYPE ATTRIBUTE KEY ATTRIBUTE MULTIVALUED ATTRIBUTE COMPOSITE ATTRIBUTE DERIVED ATTRIBUTE TOTAL PARTICIPATION OF E 2 IN R CARDINALITY RATIO 1:N FOR E 1 :E 2 IN R Key CONSTRAINT (min, max) ON PARTICIPATION OF E IN R Symbol E1E1 R E2E2 E1E1 R E2E2 R (min,max) E N Chen Qian Univ. of Kentucky

More ER Attribute of a relationship type: To describe some properties of the relationship. 6/11/201634Chen Qian Univ. of Kentucky name Employees ssn lot Works_In since dname budget did Departments

35 More ER dependentemployee IS_DEPEN An arrow indicates that given an entity, we can uniquely determine the other entity of the relationship. departmentemployee MANAGE (1,1) (0,N) (0,1)

36 ER-Design Principles Avoid redundancy. Limit the use of weak entity sets. Don’t use an entity set when an attribute will do. Limit the use of multivalued or composite attributes.

37 Avoiding Redundancy Redundancy occurs when we say the same thing in two different ways. Redundancy wastes space (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.

Example of inconsistency Suppose in a DB, a student is stored as an entity with an attribute advisor, a professor is also stored as an entity with a multi-valued attribute advisees. So…. If a student changes her advisor, and we only make changes of the student entity. Inconsistency happens because the professor entity still includes her as an advisee. The right way is: 6/11/201638Chen Qian Univ. of Kentucky

39 Consistent ER studentprofessor advised name

More Example Assume we would like to set up a database for a wine distribution company. Wine Manufacture 40

41 Example BeersManfs ManfBy name manf addr

42 Example: redundancy BeersManfs ManfBy name This design states the manufacturer of a beer twice: as an attribute and as a related entity. name manf addr

43 Example Beers namemanfmanfAddr

44 Example: redundancy and losing information Beers name This design repeats the manufacturer’s address once for each beer; loses the address if there are temporarily no beers for a manufacturer. manfmanfAddr

45 Example BeersManfs ManfBy name addr

46 Example BeersManfs ManfBy name This design gives the address of each manufacturer exactly once. nameaddr

47 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.

48 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.

Limit the use of multivalued or composite attributes 6/11/2016Chen Qian Univ. of Kentucky49 Because they can be converted to entities, which are easier to manage Manfs nameaddr beer

Limit the use of multivalued or composite attributes 6/11/2016Chen Qian Univ. of Kentucky50 Because they can be converted to entities, which are easier to manage BeersManfs ManfBy name addr

Decision making 6/11/2016Chen Qian Univ. of Kentucky51 Entity vs. Attribute

52 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 non-key attribute. or It is the “many” in a many-one or many-many relationship.

53 Example: Bad BeersManfs ManfBy name

54 Example: Bad BeersManfs ManfBy name 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. name

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

56 Example: Good BeersManfs ManfBy name Manfs deserves to be an entity set because of the non-key attribute addr. Beers deserves to be an entity set because it is the “many” of the many-one relationship ManfBy. nameaddr

57 ER Case Study I Works_In does not allow an employee to work in a department for two or more periods. We want to record several values of the descriptive attributes for each instance of this relationship. name Employees ssn lot Works_In from to dname budget did Departments dname budget did name Departments ssn lot Employees Works_In Duration from to 57 6/11/2016

58 ER Case Study I We want to record several values of the descriptive attributes for each instance of this relationship. Why not dname budget did name Departments ssn lot Employees Works_In Duration from to 586/11/2016 dname budget did name Departments ssn lot Employees Works_In to from

6/11/ ER Case study II Design a database representing cities, counties, and states For states, record name and capital (city) For counties, record name, area, and location (state) For cities, record name, population, and location (county and state) Assume the following: Names of states are unique Names of counties are only unique within a state Names of cities are only unique within a county A city is always located in a single county A county is always located in a single state

6/11/ Case study : first design County area is repeated for every city in the county  Redundancy is bad.  What else? State capital should really be a city  Should “reference” entities through explicit relationships I didn’t say a city name is unique within a state! Cities In States name capital name population county_area county_name 606/11/2016

61 Case study : second design Technically, nothing in this design could prevent a city in state X from being the capital of another state Y, but oh well… Cities IsCapitalOf name population Counties name area name In States 616/11/2016

Summary of Conceptual Design Conceptual design follows requirements analysis, Yields a high-level description of data to be stored ER model popular for conceptual design Constructs are expressive, close to the way people think about their applications. Basic constructs: entities, relationships, and attributes (of entities and relationships). Note: There are many variations on ER model.

Summary of ER (Contd.) ER design is subjective. There are often many ways to model a given scenario! Analyzing alternatives can be tricky, especially for a large enterprise. Common choices include: Entity vs. attribute, entity vs. relationship, binary or n-ary relationship.

Homework Quiz (close book) Beginning of next class 10 mins Project Find your collaborator 6/11/201664