Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Databases CSU 07203

Similar presentations


Presentation on theme: "Fundamentals of Databases CSU 07203"— Presentation transcript:

1 Fundamentals of Databases CSU 07203
The Institute of Finance Management FCIM BCS & BIT Year I -2016/2017 Entity Relationship (ER) Model

2 Entity Relationship (ER) Model
Logistics Instructor: Siphy, A. S(Mr.) Office: Block D, 020 Consultation Time Thursdays 14:00 -15:00 HRS Or By appointment Entity Relationship (ER) Model

3 Entity Relationship (ER) model
References; Elmasri/Navathe: Fundamentals of DB system, 4th Ed, Ch. 3-5, ) Rob/Cornel: Database systems 6 ed. Entity Relationship (ER) Model

4 Data Modeling Using the Entity-Relationship (ER) Model

5 Entity Relationship (ER) Model
In this lecture; ER models Entities Relationships Attributes Business rules ER Diagrams (ERDs) Entity Relationship (ER) Model

6 Entity Relationship (ER) Model
Objectives To illustrate how relationships between entities are defined and refined. To know how relationships are incorporated into the database design process. To describe how ERD components affect database design and implementation. Entity Relationship (ER) Model

7 Entity Relationship (ER) Model
Objective.. Describe the Conceptual Database Design Describe Major components of ER diagram Compare and evaluate given ER-diagrams. Evaluate the significance of the ER-model for DB design. Describe why understanding of organizational data is important. Argue why unambiguous representation of data in logical terms is needed for implementing a database that will effectively serve the needs of management Understanding the business rules Entity Relationship (ER) Model

8 Database Design Before we look at how to create and use a database we’ll look at how to design one Need to consider What tables, keys, and constraints are needed? What is the database going to be used for? Conceptual design Build a model independent of the choice of DBMS hardware platform that is used to implement the database Logical design Create the database in a given DBMS Physical design How the database is stored in hardware Entity Relationship (ER) Model

9 What is Conceptual Database Design?
Process of describing the data, relationships between the data and the constraints on the data. After analysis - Gather all the essential data required and understand how the data are related The focus is on the data, rather than on the processes. The output of the conceptual database design is a Conceptual Data Model ( + Data Dictionary) Entity Relationship (ER) Model

10 Gathering Information for Conceptual Data Modeling
Two perspectives Top-down Data model is derived from an intimate understanding of the business. Bottom-up Data model is derived by reviewing specifications and business documents. Entity Relationship (ER) Model

11 Entity-Relationship (ER) Modeling.
1976 proposed by Peter Chen ER Modelling is used for conceptual database design a top-down approach to database design. The basic concepts of the E-R model include.. Entity types Relationship types and Attributes Entity Relationship (ER) Model

12 Entity Relationship (ER) Model
E-R Modeling (Cont.) ER Models are often represented as ER diagrams (ERDs) ERD is widely used in database design Represents conceptual level of a database system Describes things and their relationships in high level Can identify some problems in a design The ERDs represent three main components Entities, Attributes & Relationships ERD example Lecturer ID Name Course Tutors Student Studies Module Entity Relationship (ER) Model

13 Entities Entities represent objects or things of interest
Physical things like students, lecturers, employees, products More abstract things like modules, orders, courses, projects Entity Relationship (ER) Model

14 Entity Relationship (ER) Model
Entity type & Sets Entities have a general type /class called entity type. Entity type a class of entities that have the same set of attributes An entity set is a set of entities of the same type that share the same properties. Example: set of all persons, companies, trees, holidays Entity Relationship (ER) Model

15 Entity Relationship (ER) Model
Entities… More examples of entities: Person: EMPLOYEE, STUDENT, PATIENT Place: STORE, WAREHOUSE Object: MACHINE, PRODUCT, CAR Event: SALE,REGISTRATION, RENEWAL Concept: ACCOUNT, COURSE Guidelines for naming and defining entity types: An entity type name is a singular noun An entity type should be descriptive and specific and concise Event entity types should be named for the result of the event, not the activity or process of the event. Entity Relationship (ER) Model

16 Diagramming Entities - example
In an ER Diagram, an entity is usually drawn as a box with rounded corners/ rectangular shape The box is labelled with the name of the class of objects represented by that entity Lecturer ID Name Course Tutors Student Studies Module Diagramming Entities - example Entity Relationship (ER) Model

17 Attributes Attributes are facts, aspects, properties, or details about an entity Attributes have A name An associated entity Domains of possible values Values from the domain for each instance of the entity they are belong to Entity Relationship (ER) Model

18 Entity Relationship (ER) Model
Attributes.. Example of entity types and associated attributes: STUDENT: Student_ID, Student_Name, Home_Address, Phone_Number, Major Guidelines for naming attributes: An attribute name is a noun. An attribute name should be unique To make an attribute name unique and clear, each attribute name should follow a standard format Similar attributes of different entity types should use similar but distinguishing names. Entity Relationship (ER) Model

19 Diagramming Attributes
In an ER Diagram attributes may be drawn as ovals Each attribute is linked to its entity by a line The name of the attribute is written in the oval Lecturer ID Name Course Tutors Student Studies Module Entity Relationship (ER) Model

20 Entity Relationship (ER) Model
Attributes -Types An entity is represented by a set of attributes, that is descriptive properties possessed by all members of an entity set. Classifications of attributes: Required vs. Optional Attributes Simple vs. Composite Attribute Single-Valued vs. Multivalued Attribute Stored vs. Derived Attributes Identifier Attributes - keys Attribute types: Simple and composite attributes. Single-valued and multi-valued attributes E.g. multi-valued attribute: phone-numbers, project, hobby and so on Derived attributes Can be computed / derived from other attributes E.g. age, given date of birth Entity Relationship (ER) Model

21 Required vs. Optional Attributes
Example: entity – ONLINE_ACCOUNT Required attributes (Not NULL) Account_ID Password Owner_Name Optional attributes (NULL) Phone_Number Password_Hint Entity Relationship (ER) Model

22 Entity Relationship (ER) Model
Figure 1 – A composite attribute Composite: Is an attribute composed of multiple components, each with an independent existence Composite attribute An attribute broken into component parts component attributes Entity Relationship (ER) Model 12

23 Entity Relationship (ER) Model
Figure 2 – Entity with a Multivalued attribute (Skill) and derived attribute (Years_Employed) Multivalued: Is one that holds multiple values for a single entity Derived: is one that represents a value that is derivable from the value of a related attribute or set of attributes , not necessarily in the same entity Derived from date employed and current date Multivalued: an employee can have more than one skill Entity Relationship (ER) Model 13

24 Entity Relationship (ER) Model
Figure 3 – An attribute that is both Multivalued and composite Entity Relationship (ER) Model 37

25 Entity Relationship (ER) Model
Identifiers (Keys) Identifier (Key) - An attribute (or combination of attributes) that uniquely identifies individual instances of an entity type Candidate Key – an attribute that could be a key. Examples (for STUDENT, PERSON)? Simple Key versus Composite Key Entity Relationship (ER) Model 6

26 Entity Relationship (ER) Model
Figure 4 Simple key attribute The key is underlined Entity Relationship (ER) Model 14

27 Entity Relationship (ER) Model
Figure 5 Composite key attribute Flight_Number Date Entity Relationship (ER) Model 15

28 Relationship name: writes
Relationships Associations between instances of one or more entity types that is of interest Given a name that describes its function. relationship name is an active or a passive verb. Relationship name: writes Book Author An author writes one or more books A book can be written by one or more authors. Entity Relationship (ER) Model

29 Entity Relationship (ER) Model
Relationships.. Relationships have A name A set of entities that participate in them A degree - the number of entities that participate (most have degree 2) A cardinality ratio Entity Relationship (ER) Model

30 Diagramming Relationships
Relationships are links between two entities The name is given in a diamond box The ends of the link show cardinality Lecturer ID Name Course Tutors Student Studies Module One Many Entity Relationship (ER) Model

31 Cardinality and Connectivity
Relationships can be classified as either One – to – One (1:1) One – to – Many(1:M) Many – to –Many(N:M) Cardinality : minimum and maximum number of instances of Entity B that can (or must be) associated with each instance of entity A. Connectivity Entity Relationship (ER) Model

32 Cardinality Ratios.. One to many (1:M) Many to many (M:M)
Each entity in a relationship can participate in zero, one, or more than one instances of that relationship Three types of relationships (examples) One to one (1:1) Each lecturer has a unique office One to many (1:M) A lecturer may tutor many students, but each student has just one tutor Many to many (M:M) Each student takes several modules, and each module is taken by several students Entity Relationship (ER) Model

33 Cardinality and Connectivity… examples
Professor teaches Class Professor Class teaches A professor teaches class OR A class is taught by professor How Many?? Entity Relationship (ER) Model

34 Cardinality and Connectivity…examples
1 M Professor teaches Class (1,4) (1,1) Cardinality Connectivity Professor Class teaches (1,1) (1,4) Cardinality Entity Relationship (ER) Model

35 ER Modeling Notations -summary
Notation uses three main constructs Data entities Relationships Attributes Chen Model & Crow’s Foot Model Entity Relationship (ER) Model

36 Entity Relationship (ER) Model
Chen Notation Association between the instances of one or more entity types EntityName Verb Phrase AttributeName named property or characteristic of an entity Person, place, object, event or concept about which data is to be maintained Represents a set or collection of objects in the real world that share the same properties Entity set Entity Relationship (ER) Model

37 Entity Relationship (ER) Model
Crow’s Foot Notation Entity Attribute Relationship EntityName EntityName Verb phrase List of Attributes Acceptable Entity Relationship (ER) Model

38 Entity Relationship (ER) Model
Connectivity Chen Model 1 to represent one. M to represent many Crow’s Foot 1 M Mandatory one , means (1,1) One many One or many Entity Relationship (ER) Model

39 Entity Relationship (ER) Model
Relationships…. Relationship Type vs. Relationship Instance Degree of a relationship Cardinality of a relationship Associative Entity – combination of relationship and entity Entity Relationship (ER) Model

40 Entity Relationship (ER) Model
Relationship Sets A relationship set is a mathematical relation among n  2 entities, each taken from entity sets {(e1, e2, … en) | e1  E1, e2  E2, …, en  En} where (e1, e2, …, en) is a relationship Example: (Hayes, A-102)  depositor Entity Relationship (ER) Model

41 Relationship Set borrower example
Entity Relationship (ER) Model

42 Relationship Sets (Cont.)
Entity Relationship (ER) Model

43 Entity Relationship (ER) Model
Figure 6 –a relationship with an attribute attribute of the relationship The relationship type is modeled as the diamond and lines between entity types Entity Relationship (ER) Model 20

44 Entity Relationship (ER) Model
Degree of a relationship is the number of entity types that participate in it Entities of two different types related to each other One entity related to another of the same entity type Entities of three different types related to each other Entity Relationship (ER) Model 8

45 Entity Relationship (ER) Model
Degree of relationship -Examples Refers to number of entity sets that participate in a relationship set. It indicates the number of associated entities Entity Relationship (ER) Model

46 Cardinality of a Relationship
One-to-One Each entity in the relationship will have exactly one related entity One-to-Many An entity on one side of the relationship can have many related entities, but an entity on the other side will have a maximum of one related entity Many-to-Many Entities on both sides of the relationship can have many related entities on the other side Entity Relationship (ER) Model

47 Cardinality of a Relationship-examples
One to One One to Many One to One Note: Some elements in A and B may not be mapped to any elements in the other set Entity Relationship (ER) Model

48 Cardinality of a Relationship- examples
Many to one Many to Many Note: Some elements in A and B may not be mapped to any elements in the other set Entity Relationship (ER) Model

49 Entity Relationship (ER) Model
Figure 10 –Examples of relationships of different degrees –Unary relationships Entity Relationship (ER) Model 22

50 Entity Relationship (ER) Model
Figure 11 –examples of relationships of different degrees –Binary relationships Entity Relationship (ER) Model 23

51 Entity Relationship (ER) Model
Figure 12 –examples of relationships of different degrees –Ternary relationships Note: a relationship can have attributes of its own Entity Relationship (ER) Model 24

52 Cardinality Constraints
Cardinality Constraints - the number of instances of one entity that can or must be associated with each instance of another entity Minimum Cardinality. Examples? If zero, then optional If one or more, then mandatory Maximum Cardinality. Examples? The maximum number Entity Relationship (ER) Model 29

53 Entity Relationship (ER) Model
Cardinalities Mandatory one Mandatory many Optional one Optional many 11 18 Entity Relationship (ER) Model

54 Entity Relationship (ER) Model
Figure 13a –Basic relationship Figure 13b –Optional cardinalities with unary degree, one-to-one relationship Entity Relationship (ER) Model 1

55 Maximum Cardinality Constraint
max cardinality constraint Entity Relationship (ER) Model 41

56 Entity Relationship (ER) Model
Examples of multiple relationships –employees and departments Entities can be related to one another in more than one way Entity Relationship (ER) Model 40

57 Attributes or Relationship?
Using relationships to link related attributes –composite, Multivalued attribute versus relationship Attributes can be transformed to relationships Entity Relationship (ER) Model

58 Entity Relationship (ER) Model
Associative Entities It’s an entity – it has attributes AND it’s a relationship – it links entities together When should a relationship with attributes be an associative entity? All relationships for the associative entity should be many The associative entity could have meaning independent of the other entities The associative entity should have at least one or more attributes other than the identifier The associative entity may participate in other relationships other than the entities of the associated relationship Ternary relationships should be converted to associative entities Entity Relationship (ER) Model

59 Removing M:M Relationships
Many to many relationships are difficult to represent We can split a many to many relationship into two one to many relationships An entity represents the M:M relationship Enrolment Student Module In Has Student Module Studies Entity Relationship (ER) Model

60 Entity Relationship (ER) Model
An associative entity (CERTIFICATE) Entity Relationship (ER) Model 21

61 Entity Relationship (ER) Model
Bill of materials structure Entity Relationship (ER) Model 27

62 Entity Relationship (ER) Model
Figure ; Ternary relationship as an associative entity Entity Relationship (ER) Model 36

63 Strong vs. Weak Entities
Strong entities exist independently of other types of entities has its own unique identifier represented with single-line rectangle Weak entity dependent on a strong entity…cannot exist on its own does not have a unique identifier represented with double-line rectangle Identifying relationship links strong entities to weak entities represented with double line diamond Entity Relationship (ER) Model

64 Figure ; Example of a weak entity and its identifying relationship
-ER notation Strong entity Identifying relationship Weak entity

65 Entity Relationship (ER) Model
Basic E-R notation Relationship symbols Attribute symbols Entity symbols A special entity that is also a relationship Relationship degrees specify number of entity types involved Relationship cardinalities specify how many of each entity type is allowed Entity Relationship (ER) Model 8

66 Entity Relationship (ER) Model
Sample E-R Diagram Attribute Supplier_ID Supplier_Name Supplier_Address Entity Relationship (ER) Model 3

67 Entity Relationship (ER) Model
Design Issues Identify business rules Construct ERD Use of entity sets vs. attributes Choice mainly depends on the structure of the enterprise being modeled, and on the semantics associated with the attribute in question. Use of entity sets vs. relationship sets Possible guideline is to designate a relationship set to describe an action that occurs between entities Binary versus n-ary relationship sets Although it is possible to replace any non-binary (n-ary, for n > 2) relationship set by a number of distinct binary relationship sets, a n-ary relationship set shows more clearly that several entities participate in a single relationship. Placement of relationship attributes Entity Relationship (ER) Model

68 Making ER Models To make an E/R model you need to identify
Entities Attributes Relationships Cardinality ratios from a description General guidelines Since entities are things or objects they are often nouns in the description Attributes are facts or properties, and so are often nouns also Verbs often describe relationships between entities Entity Relationship (ER) Model

69 Entity Relationship (ER) Model
Business Rules Brief, precise, and unambiguous descriptions of a policies, procedures, or principles within a specific organization Apply to any organization that stores and uses data to generate information Description of operations that help to create and enforce actions within that organization’s environment Entity Relationship (ER) Model

70 Business Rules (continued)
Must be rendered in writing Must be kept up to date Sometimes are external to the organization Must be easy to understand and widely disseminated Describe characteristics of the data as viewed by the company Entity Relationship (ER) Model

71 Discovering Business Rules
Sources of Business Rules: Company managers Policy makers Department managers Written documentation Procedures Standards Operations manuals Direct interviews with end users Entity Relationship (ER) Model

72 Discovering Business Rules (continued)
Generally, Nouns translate into entities Verbs translate into relationships among entities Relationships are bi-directional Entity Relationship (ER) Model

73 Business Rules Examples - ER Diagrams
Draw the ERD for the following scenarios: Each patient has one or more patient histories; each instance of patient history belongs to one patient. An employee may be recorded as having many jobs; a particular job may be recorded as having been held by many employees. A customer may place many orders; an order is specific to one customer. Entity Relationship (ER) Model

74 Example A university consists of a number of departments. Each department offers several courses. A number of modules make up each course and a module can be part of many courses. Students enrol in a particular course and take modules towards the completion of that course. Each module is taught by a lecturer from the appropriate department, and each lecturer tutors a group of students Entity Relationship (ER) Model

75 Example - Entities A university consists of a number of departments. Each department offers several courses. A number of modules make up each course and a module can be part of many courses. Students enrol in a particular course and take modules towards the completion of that course. Each module is taught by a lecturer from the appropriate department, and each lecturer tutors a group of students Entity Relationship (ER) Model

76 Example - Relationships
A university consists of a number of departments. Each department offers several courses. A number of modules make up each course and a module can be part of many courses. Students enrol in a particular course and take modules towards the completion of that course. Each module is taught by a lecturer from the appropriate department, and each lecturer tutors a group of students Entity Relationship (ER) Model

77 Example - E/R Diagram Department Course Module Lecturer Student
Entities: Department, Course, Module, Lecturer, Student Department Course Module Lecturer Student Entity Relationship (ER) Model

78 Example - E/R Diagram Department Course Module Lecturer Student
Each department offers several courses Offers Department Course Module Lecturer Student Entity Relationship (ER) Model

79 Example - E/R Diagram Department Course Module Lecturer Student
A number of modules make up each courses Offers Department Includes Course Module Lecturer Student Entity Relationship (ER) Model

80 Example - E/R Diagram Department Course Module Lecturer Student
Students enrol in a particular course Offers Department Includes Course Module Lecturer Enrols In Student Entity Relationship (ER) Model

81 Example - E/R Diagram Department Course Module Lecturer Student
Students … take modules Offers Department Includes Course Module Lecturer Takes Enrols In Student Entity Relationship (ER) Model

82 Example - E/R Diagram Department Course Module Lecturer Student
Each module is taught by a lecturer Offers Department Includes Teaches Course Module Lecturer Takes Enrols In Student Entity Relationship (ER) Model

83 Example - E/R Diagram Department Course Module Lecturer Student
a lecturer from the appropriate department Offers Employs Department Includes Teaches Course Module Lecturer Takes Enrols In Student Entity Relationship (ER) Model

84 Example - E/R Diagram Department Course Module Lecturer Student
each lecturer tutors a group of students Offers Employs Department Includes Teaches Course Module Lecturer Takes Enrols In Tutors Student Entity Relationship (ER) Model

85 Entity Relationship (ER) Model
Example - E/R Diagram Draw an ERD for a small college database comprising the entity types: DEPARTMENT, COURSE, STUDENT and LECTURER.  Each department has many lecturers, one of whom is the head of department. A lecturer belongs to only one department. Each department offers many different courses, and many lecturers can teach on a single course. Lecturers can also teach on more than one course. A student may enrol for many courses offered by different departments. Entity Relationship (ER) Model

86 Symbols Used in E-R Notation-summary
The attributes are connected using lines to the entities. If the attribute is simple or single valued a single line is used If the attributes is derived a dotted line is used If it is multi-valued then double line are used If the attribute is composite, its component attributes are shown as ellipse emanating from the composite attribute Entity Relationship (ER) Model

87 Symbols Used in E-R Notation(cont.)
Entity Relationship (ER) Model

88 Alternative E-R Notations
Entity Relationship (ER) Model


Download ppt "Fundamentals of Databases CSU 07203"

Similar presentations


Ads by Google