Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENTITY RELATIONSHIP MODELLING

Similar presentations


Presentation on theme: "ENTITY RELATIONSHIP MODELLING"— Presentation transcript:

1 ENTITY RELATIONSHIP MODELLING
Ref: Natasha Alechina, Database Systems Lecture 4 Semester Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei

2 Contents Database Design Degrees of Data Abstraction
Entity Relationship Modelling Entity Relationship Diagrams Entities Diagramming Entities Attribute *Words with underline can be clicked on

3 Contents Diagramming Attributes Relationships Cardinality Ratios
Diagramming Relationships Removing M:M Relationships Types of ER Modelling Symbols Making ER Models *Words with underline can be clicked on

4 Cont. Contents Entities and Attributes One to One Relationships
Redundant Relationships Making ER Diagrams Debugging Designs *Words with underline can be clicked on

5 Database Design Before looking at how to create and use a database, we need to look at how to design one. We may change the instance of the database anytime but not the schema. Therefore a good design is required. Need to consider: What tables, keys, and constraints are required? What is the database going to be used for?

6 Cont. Database Design There are few types of design: Conceptual design
Build a model independent of the choice of DBMS Logical design Create the database in a given DBMS Physical design How the database is stored in hardware.

7 Degrees of Data Abstraction

8 Entity Relationship Modelling
ER Modelling is used for conceptual design. Entities – objects or items of interest. Attributes – facts about, or properties of, an entity. Relationships – links between entities. E.g. In a University database we might have entities for Students, Modules and Lectures. Students might have attributes such as their ID, Name, and Course, and could have relationships with Modules (enrolment) and Lecturers.

9 Entity Relationship Diagrams
ER Models are often represented as ER diagrams (ERD) that: Give a conceptual view of the database Are independent of the choice of DBMS Can identify some problems in a design.

10 Entities Entities represent objects or things of interest
Physical things like students, lecturers, employees, product. More abstract things like modules, orders, courses, projects.

11 Cont. Entities Entities have
A general type of class, such as Lecturer or Module Instances of that particular type, such as Miss Amal, Miss Azu are instances of Lecturer. Attributes (such as name, address)

12 Diagramming Entities In an ERD an entity is usually drawn as a box with rounded corners. The box is labelled with the name of the class of objects represented by that entity.

13 Attribute Attributes are facts, aspects, properties or details about an entity Students have IDs, Name, courses, address,… Lecturers have Name, Department,… Modules have codes, titles, credit unit, semesters,…

14 Cont. Attribute 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

15 Diagramming Attributes
In an ERD an 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.

16 Relationships Relationships are an association between two or more entities. Each Student take several Modules Each Module is taught by a Lecturer Each Employee works for a single Department

17 Cont. 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

18 Cardinality Ratios Each entity in a relationship can participate in zero, one, or more than one instances of that relationship. This leads to 3 types of relationship. One to one (1:1) One to many (1:M) Many to many (M:M)

19 Cont. Cardinality Ratios
One to one (1:1) Each entity in the relationship will have exactly one related entity. One to many (1:M) 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 (M:N) Entities on both sides of the relationship can have many related entities on the other side.

20 Cont. Cardinality Ratios
One to one (1:1) E.g. Each lecturer has a unique office. Each student has a unique student ID

21 Cont. Cardinality Ratios
One to many (1:M) E.g. Each class can be used by different courses. Each book in the library can be borrowed by different students.

22 Cont. Cardinality Ratios
Many to one (M:1) E.g. Many lecturers are under a department. Many students are under SICT.

23 Cont. Cardinality Ratios
Many to many (M:N) E.g. Each student takes several modules, and each module is taken up by several students.

24 Diagramming Relationships
Relationships are links between two entities The name is given in a diamond box The ends of the link show cardinality

25 Removing M:M Relationships
Many to many relationship are difficult to represent. Therefore it should be split into 2 one to many relationships

26 Types of ER Modelling Symbols
There are four types of ER modelling symbols: Chen Moved conceptual design into practical database design arena. Crow’s Foot Cannot detail all cardinalities Rein85 Operates at higher level of abstraction IDEF1X Uses fewer symbols.

27 Cont. Types of ER Modelling Symbols

28 Making ER Models To make an ER model you need to identify: Entities
Attributes Relationships Cardinality From the description/business rules of the organization.

29 Cont. Making ER Models 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 as well. Verbs often describe relationships between entities.

30 Cont. Making ER Models Example – Find the entities A university consists of a number of departments. Each department offers several courses. A number of modules make up each course. Students enroll 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.

31 Cont. Making ER Models Example – Find the entities A university consists of a number of departments. Each department offers several courses. A number of modules make up each course. Students enroll 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.

32 Cont. Making ER Models Example – Relationships A university consists of a number of departments. Each department offers several courses. A number of modules make up each course. Students enroll 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.

33 Cont. Making ER Models Entities: Department Course, Module, Lecturer, Student

34 Cont. Making ER Models Each department offers several courses

35 Cont. Making ER Models A number of modules make up each courses

36 Cont. Making ER Models Students enroll in a particular course

37 Cont. Making ER Models Students … take modules

38 Cont. Making ER Models Each module is taught by a lecturer

39 Cont. Making ER Models A lecturer from the appropriate department

40 Cont. Making ER Models Each lecturer tutors a group of students

41 Entities and Attributes
Sometimes it is hard to tell if something should be an entity or an attribute. They both represent objects or facts about the world. They both are often represented by nouns in descriptions.

42 Cont. Entities and Attributes
General guidelines Entities can have attributes but attributes have no smaller parts Entities can have relationships between them, but an attribute belongs to a single entity

43 Cont. Entities and Attributes
Example We want to represent information about products in a database. Each product has a description, a price and a supplier. Suppliers have addresses, phone numbers, and names. Each address is made up of a street address a city, and a postcode.

44 Cont. Entities and Attributes
Example Which is entity? which is attribute? Each product has a description, a price and a supplier. Suppliers have addresses, phone numbers, and names. Each address is made up of a street address a city, and a postcode.

45 Cont. Entities and Attributes
Products, suppliers, and addresses all have smaller parts. Therefore they can be made into entities. The others have no smaller parts and are belong to a single entity. Therefore they can be made into attributes.

46 Cont. Entities and Attributes

47 Cont. Entities and Attributes
Each product has a supplier Each product has a single supplier but there is nothing to stop a supplier supplying many products. (M:1) Each supplier has an address A supplier has a single address It does not seem sensible for two different suppliers to have the same address. (1:1)

48 Cont. Entities and Attributes

49 One to One Relationships
Some relationships between entities, A and B, might be redundant if: It is a 1:1 relationship between A and B. Every A is related to a B and every B is related to an A.

50 One to One Relationships
Example The supplier-address relationship: Is one to one (1:1) Every supplier has an address No address that are not related to a supplier is available.

51 Redundant Relationships
We can merge the two entities that take part in a redundant relationship together. They become a single entity. The new entity has all the attributes of the old one.

52 Cont. Redundant Relationships

53 Making ER Diagrams From a description of the requirements, identify the: Entities Attributes Relationships Cardinality ratios of the relationships

54 Cont. Making ER Diagrams
Draw the ER diagram and then: Look at one to one relationships as they might be redundant. Look at many to many relationships as they might need to be split into two one to many links.

55 Debugging Designs With a bit of practice ER Diagrams can be used to plan queries. You can look at the diagram and figure our how to find useful information. If you can’t find the information you need, you may need to change the design.

56 Cont. Debugging Designs
Example How can you find a list of students who are enrolled in Database Systems?

57 Cont. Debugging Designs
Find the instance of the Module entity with title ‘Database Systems’ Find instances of the Enrolment entity with the same Code as the result of (1) For each instance of Enrolment in the result of (2) find the corresponding Student.

58 Class Activity~~ Instructions: Groupings
write down the name of the group member on the A3 paper. Read the given description properly Discuss within the group. Answer the Question by writing them down on the A3 paper provided. Once completed, keep it to your own group, instruction will be given when the time ends.

59 Cont. Class Activity~~ A database will be made to store information about patients in a hospital. On arrival, each patient’s personal details (name, address, and telephone number) are recorded where possible, and they are given an admission number. They are then assigned to a particular ward (Accident and Emergency, Cardiology, Oncology, etc.). In each ward there are number of doctors and nurses. A patient will be treated by one doctor and several nurses over the course of their stay, and each doctor and nurse may be involved with several patients at any given time.

60 Cont. Class Activity~~ Identify the entities, attributes, relationship, and cardinality ratios from the description. Draw an entity-relationship diagram showing the items you identified. (merge any redundant relation) Many-to-many (M:M) relationships are hard to represent in SQL tables. Explain why many-to-many relationships cause problems in SQL tables, and show how these problems may be overcome.

61 Schema Diagram for University Database

62 Ref: Dr Natasha Alechina, University of Nottingham
Lecture Slides by Tan Szu Tak, SICT, Politeknik Brunei


Download ppt "ENTITY RELATIONSHIP MODELLING"

Similar presentations


Ads by Google