Presentation on theme: "ENTITY RELATIONSHIP MODELLING"— Presentation transcript:
1 ENTITY RELATIONSHIP MODELLING Ref: Natasha Alechina, Database Systems Lecture 4SemesterModule Coordinator Tan Szu TakSchool of Information and Communication Technology, Politeknik Brunei
2 Contents Database Design Degrees of Data Abstraction Entity Relationship ModellingEntity Relationship DiagramsEntitiesDiagramming EntitiesAttribute*Words with underline can be clicked on
3 Contents Diagramming Attributes Relationships Cardinality Ratios Diagramming RelationshipsRemoving M:M RelationshipsTypes of ER Modelling SymbolsMaking ER Models*Words with underline can be clicked on
4 Cont. Contents Entities and Attributes One to One Relationships Redundant RelationshipsMaking ER DiagramsDebugging Designs*Words with underline can be clicked on
5 Database DesignBefore 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 DBMSLogical designCreate the database in a given DBMSPhysical designHow the database is stored in hardware.
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 databaseAre independent of the choice of DBMSCan 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 ModuleInstances of that particular type, such as Miss Amal, Miss Azu are instances of Lecturer.Attributes (such as name, address)
12 Diagramming EntitiesIn 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 AttributeAttributes are facts, aspects, properties or details about an entityStudents 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 valuesValues 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 RelationshipsRelationships are an association between two or more entities.Each Student take several ModulesEach Module is taught by a LecturerEach Employee works for a single Department
17 Cont. Relationships Relationships have A name A set of entities that participate in themA degree – the number of entities that participate (Most have degree 2)A cardinality ratio
18 Cardinality RatiosEach 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:ChenMoved conceptual design into practical database design arena.Crow’s FootCannot detail all cardinalitiesRein85Operates at higher level of abstractionIDEF1XUses fewer symbols.
28 Making ER Models To make an ER model you need to identify: Entities AttributesRelationshipsCardinalityFrom 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 ModelsExample – Find the entitiesA 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 ModelsExample – Find the entitiesA 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 ModelsExample – RelationshipsA 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 ModelsEntities: Department Course, Module, Lecturer, Student
34 Cont. Making ER ModelsEach department offers several courses
35 Cont. Making ER ModelsA number of modules make up each courses
36 Cont. Making ER ModelsStudents enroll in a particular course
38 Cont. Making ER ModelsEach module is taught by a lecturer
39 Cont. Making ER ModelsA lecturer from the appropriate department
40 Cont. Making ER ModelsEach 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 guidelinesEntities can have attributes but attributes have no smaller partsEntities 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.
47 Cont. Entities and Attributes Each product has a supplierEach product has a single supplier but there is nothing to stop a supplier supplying many products. (M:1)Each supplier has an addressA supplier has a single addressIt does not seem sensible for two different suppliers to have the same address. (1:1)
53 Making ER DiagramsFrom a description of the requirements, identify the:EntitiesAttributesRelationshipsCardinality 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 DesignsWith 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 properlyDiscuss 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.