Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 2. FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)

Similar presentations


Presentation on theme: "CHAPTER 2. FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)"— Presentation transcript:

1 CHAPTER 2. FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)
Chapter 2- ERD

2 2.1 Entity Relationship (ER) Model
2.1.1 Introduction ER model is the constructs and conventions used to create a model of the user data. The results are documented in an entity relationship diagram (ERD) ERD is a diagram that depicts entity relationship model entities, attributes and relations. It also displays connectivity and cardinality. Chapter 2- ERD

3 e.g : A Car Purchasing Model
FACTORY PRODUCE CUSTOMER PURCHASED BY ENTITY RELATIONSHIP The diagram above shows a car purchasing model that involves the relationship between the factory, car and customer. Here, we can see clearly that factory produces car and a customer purchases the car Entity : FACTORY, CAR & CUSTOMER Relationship : Produce & Purchased by. Chapter 2- ERD

4 e. g: ER Model of Book Information System
PUBLISHER publish Written by BOOK AUTHOR Books at E-Book bookstore are recorded. Information about publisher and the author will also be recorded to make sure that the process of searching for the book is easier Chapter 2- ERD

5 Transformed to ERD PUBLISHER publish BOOK city Step 1 : 1 M
Publisher_Code Publisher_Name city Book_Code Title Price Type Step 1 : 1 M Relationship One to Many (1:M) : One publisher can publish many books while one book can only be published by one publisher Chapter 2- ERD

6 Step 2 : M N BOOK publish AUTHOR
Book_Code Author_No Type Price Author_No M N BOOK publish AUTHOR Title Author_Name Publisher_Code Book_Code Relationship Many to Many (M:N) : One book can be written by many authors while one author can write many books Chapter 2- ERD

7 Complete ERD M 1 BOOK PUBLISHER M N AUTHOR publish Written by Type
Publisher_Name Book_Code Price Publisher_Code M 1 BOOK PUBLISHER publish M city Publisher_Code Title Written by Book_Code Author_No N AUTHOR Author_No Author_Name Chapter 2- ERD

8 2.1.2 Elements of ER Model Element Symbol Definition Entity
There are 3 elements of ER Model : Element Symbol Definition Entity A person, place, object, event or concept which you want to store information in database Attribute A property or characteristic of an entity or relationship type. Relationship Interaction of two entities represented by a verb. Chapter 2- ERD

9 2.1.3 Notation of ER Model Entity Relationship Simple Attribute
Multi valued Composite Attribute Derived Attribute Chapter 2- ERD

10 2.2 Entities And Attributes
2.2.1 Entity Definition Entity is a person, place, object, event or concept which you want to store the information in a database Chapter 2- ERD

11 Continue….. Characteristics of entities :
Must have an attributes and unique key Will become a table in a database Classification of entities : PERSON Example : Student, Employee PLACE Example : Country, Branch OBJECT Example : Product, Building EVENT Example : Student Registration, Payment CONCEPT Example : Course, Order Chapter 2- ERD

12 Continue…….. What is Entity Type ?
Entity type is a collection of entities, which share the same characteristics What is Entity Instances ? Entity instances are data for entity type Chapter 2- ERD

13 Example Two entity instances for BOOK : P01 Access 2000 Processing
M-G1 Database 76.00 Yes Entity Type : BOOK Attribute : Book_Code Book_title Publisher_Code Description Type Price Book_cover P02 Concepts of Database Management P-H1 Database 100.00 No Chapter 2- ERD

14 Attribute is a character of an entity or object.
Example : Type Price Book_Code BOOK Title Attributes for the entity BOOK are Book_code, Type, Price and Title Chapter 2- ERD

15 2.2.3 Types of Attributes Types of attributes Definition Example
Simple An attribute that holds a single value e.g: The majority of people have only one name Multi valued An attribute that have more than one value e.g: A staff may have 2 tel_no. Composite An attribute that can be broken down into component parts Derived An attribute where the values can be calculated from related attribute Name Pnone-Num State Town Postcode Address Date_of_birth Age Chapter 2- ERD

16 2.3 Relationship and Cardinality Constraint
Definition : Relationship is an association between entities, which is defined by a diamond shaped symbol in an ERD Chapter 2- ERD

17 Continue…. 2.3.2 Cardinality Constraint
Definition :The number of entity type, which is involved in a relationship. Types of cardinality constraint : a). One to One Relationship (1:1) Def : Maximum one X for each Y and one Y for each X Manager_ID Branch_ID 1 1 MANAGER manage BRANCH X Y An employee (manager) can manage only one branch at one time and each branch only has one manager. Chapter 2- ERD

18 Def : Maximum one X for each Y and possibly many Y’s for each X.
b). One to Many (1:M) Def : Maximum one X for each Y and possibly many Y’s for each X. Faculty_Name Course_Code Faculty_Name 1 M offer FACULTY COURSE X Y At university, one faculty offers many courses for students but one course is offered by one faculty only. Chapter 2- ERD

19 Def : Possibly many X’s for each Y and many Y’s for each X
c). Many to Many (M:N) Def : Possibly many X’s for each Y and many Y’s for each X Author_ID Author_ID ISDN M N Written by BOOK AUTHOR ISDN Composite entity Author_ID & ISDN : Composite Key A book may have more than one author and an author may write more than one book. Chapter 2- ERD

20 2.4 Relational Key and Integrity Constraint
2.4.1 Types of Key Types of Key Definition Candidate key An attribute or group of attributes that identifies a unique row in a relation. One of the candidate keys is chosen to be the primary key Primary Key Any of the candidates that are selected to be the key or an attribute that uniquely identifies each row in a relation. Foreign Key An attribute in a one table whose values must match the primary key in another table or whose value must be null. Attribute that act as a primary key in a related table. Composite Key A primary key that consists of more than one attribute, especially in M:N relationship. Chapter 2- ERD

21 Continue…. 2.4.2 Integrity Constraints 2 types of integrity constraint
a). Entity Integrity Requirement : All entries are unique and no part of a primary key may be null (no data). Chapter 2- ERD

22 Continue…. b). Referential Integrity
Requirement : If foreign key exist in one table then the foreign key value must reference an existing primary key value in a table to which it is related and it can be null. Chapter 2- ERD

23 Example : PUBLISHER BOOK
Publisher_Code Name City F-B1 Fajar Bakti Malaysia M-G1 McGraw Hill UK P-H1 Prentice Hall T-H1 Thompson US BOOK Book_Code Book_Title Publisher_Code Type Price P01 Access 2000 Processing M-G1 Database 76.00 P02 Teach Yourself MS Access 80.00 P03 Concepts of Database Mgmt System P-H1 100.00 P04 Pengajian Malaysia T-H1 Pengetahuan am 40.00 P05 Graphic Design F-B1 Graphic 88.00 Publisher_Code is a Primary Key for PUBLISHER table, but it is also a Foreign Key for BOOK table. Please note that Foreign Key value in table BOOK must match the Primary Key value in PUBLISHER table. Chapter 2- ERD

24 Entity Relationship Diagram (ERD)
Definition : ERD is a diagram that depicts entity relationship model entities, attributes and relations. It also displays connectivity and cardinality. A tool used to represent graphically the association between entities in a system. View a system in term of entity and relationship. Chapter 2- ERD

25 IDENTIFY RELATIONSHIP STATE CARDINALITY CONSTRAINTS
Steps to develop ERD SKETCH ERD IDENTIFY ENTITY IDENTIFY RELATIONSHIP STATE CARDINALITY CONSTRAINTS SPECIFY PRIMARY KEYS ADD ATTRIBUTES Chapter 2- ERD

26 Exercise Hospital Jaya is based in KL. This hospital has a few wards with several patients. This wards has a few types, which depends on type of patients. Patient will be recorded into file that has ID Patient, Patient Name, Address, Phone Number, IC Number, Categories either VIP or regular patient and a group of blood patient Each patient is treated by a doctor at one time but one doctor can treats a number of patients. The information of doctors recorded are : Doctor ID, name, address, phone number, IC number and specialization. The nurses will be assigned to take care of the patients. Nurses in this hospital are graded based on their experience, qualification and duration of working in the hospital. Draw a complete ERD based on the situation Chapter 2- ERD


Download ppt "CHAPTER 2. FUNDAMENTAL OF ENTITY RELATIONSHIP (ER)"

Similar presentations


Ads by Google