Professional Documents
Culture Documents
Topic 3 & 4 Entity Relationship Modelling: Er. Pradip Kharbuja
Topic 3 & 4 Entity Relationship Modelling: Er. Pradip Kharbuja
Entity
An entity can be defined as anything, which can be uniquely identified and about which data is stored in a database. A place, person, picture, concept (e.g. course, position, job) are the example of an entity. Some other examples can be student, workers, car, departments, etc.
Entity Type
An entity type is a collection of similar entities. An entity-type is a category. An entity type is a group of objects, people, concepts or other items that have the same set of properties or attributes.
The goal of ER Modelling is to produce a model of data that is nontechnical and free of ambiguities
Attributes
An attribute is a property of an entity type. The data that we want to keep about each entity within an entity type is contained in attributes. Examples of Attributes : 1. Roll number, name and grade are the attributes of Student. 2. Brand, cost and weight are the attributes of Cellphone. 3. Book name, price, author, publisher, etc. are attributes of Book.
Types of Attributes
1. Single-valued attribute 2. Multi-valued attribute 3. Simple Attribute
4. Composite Attribute
5. Key Attribute 6. Derived Attribute
7. Attribute Domain
Types of Attributes
1. Single-valued attribute : Attribute that holds a single value for an occurrence of an entity type. E.g. age, first_name, last_name, full_name, etc.
2. Multi-valued attribute : Attribute where there might be more than one value for a given occurrence of an entity type, e.g. for the 'Telephone Number', where a person or company might have many of these.
Types of Attributes
3. Simple Attribute It is composed of a single component. e.g. age, first_name, last_name, etc. But full_name is not simple attribute. Because it is composed of first_name and last_name. 4. Composite Attribute It is composed of more than one component. For example, 'address' might have city, state, country, zip code, etc.
Types of Attributes
5. Key Attribute Primary Key is a key attribute. Not Null and Unique attribute of an entity At most one attribute in each entity 6. Derived Attribute The value of the derived attribute can be derived from the values of other attributes Age of a person can be derived from the date of birth and current date i.e. age = current date date of birth.
Types of Attributes
7. Attribute Domain A domain is the set of allowable values for an attribute or number of attributes. A domain therefore limits the values that an attribute can have. For example, the domain of 'gender' would include the values 'Male' and 'Female'. Similarly, the domain of fruit would include the values 'Apple', 'Orange' etc.
Relationship
A relationship is an association of entities showing how the entities are related with each other. The examples of relationship are: Teaching is the relationship between Lecturer and Student. Buying is the relationship between Vendor and Customer. Treatment is the relationship between Doctor and Patient.
Types of Relationship
1. One-to -One (1 : 1) Each department can have only one department head. Each person can have only one age.
2.
One-to-Many (1 : N) One course can have many students registered. A lecturer may be teaching to many students.
Types of Relationship
3. Many-to-One (N : 1) Many cities come under one country. Many books can be written by one writer. Many authors can write one book. 4. Many-to-Many (M : N) An Author can write several Books, and a Book can be written by several Authors A teacher teaches many class and a class studies from many teachers.
Represents a relationship
ER Diagram
ER Diagram
Draw an ER Diagram for ClassRoom which has two attributes : room_no and building_name.
ER Diagram
Multiplicity
A teacher teaches only one subject.
Weak entity
Multi-valued Attribute
An employee has full name, age and can have more than one qualifications.
Key Attribute
Primary Key A department has Primary Key dept_no, department_name and location
Derived Attribute
The value of the derived attribute can be derived from the values of other related attributes. Age of a person can be derived from the date of birth and current date i.e. age = current date date of birth. In this example, age is the derived attribute.
Composite Attribute
Composite attribute is one which can be further subdivided into simple attributes.
Task : ER Diagram
1. Draw an ER diagram for student. 2. Draw an ER diagram for customers and loan relation. 3. Draw an ER diagram for hospital with a set of patients and medical doctors. 4. Draw an ER diagram for banking system. 5. Draw an ER diagram for car insurance company.
Relationship Degree
Relationship degree refers to the number of associated entities in a relationship. The relationship degree can be broadly classified into 1. Unary(Recursive) relationship 2. Binary relationship 3. Ternary relationship
Unary(Recursive) relationship
The number of associated entity is one. An entity related to itself is known as recursive relationship.
Binary relationship
In a binary relationship, two entities are involved. Consider the example: each department will have many workers.
Ternary relationship
In a ternary relationship, three entities are simultaneously involved. Example : Consider a project is assigned to many employee. And the project is assigned to one location.
Relationship
Illustrates an association between two entities. It has a name which is a verb. It also has cardinality.
Entity Name
PK
attribute name
is assigned to
course
student
takes
course
Passenger
Ticket
Flight
Many-to-Many Relationship
Module having many Students and Students taking many Modules
0..N 0..N
Module
Attributes ModuleID(PK) ModuleName
Taken By
Student
Attributes StudentID(PK) StudentName
Many-to-Many Relationship
Module
Attributes ModuleID(PK) ModuleName
1 0..N
0..N
ModuleStudent
Attributes ModuleID(FK) StudentID(FK)
Student
Attributes StudentID(PK) StudentName
1..N
1..N
Book
Book Author
Author
A Gardening Company
The company hires out workers as they need to. Workers in the town stay in lodgings. A lodging may have many workers in it. We are only concerned with the workers current
[Note : We are only concerned with one town. So, town is not entity here. But 'Town' is an attribute of the Lodging.]
Possible Solution
1 0..* 0..* 1
Worker
0..*
Worker Skill
Skill
Lodging
Primary Key
The PRIMARY KEY constraint uniquely identifies each record in a database table. Primary keys must contain unique values. A primary key column cannot contain NULL values. Each table should have a primary key, and each table can have only ONE primary key. departments -----------------------dept_no (PK) department_name location
Foreign Key
A FOREIGN KEY in one table points to a PRIMARY KEY in another table A FOREIGN KEY is a column or a combination of columns that is used to establish and enforce a link between two tables or entities. departments -----------------------dept_no (PK) department_name location workers -----------------emp_no (PK) first_name last_name age job_title dept_no (FK)
A Problem
A campus may have one or many staffs. Also a campus may have one or many department. 1..* 1 1 1..*
Staff
Campus
Department
A Problem
Campus
Campus ID
C1 C2 C3
Staff
Staff ID S1 S2 S3 Name Eric Hudson Sandra Smith Malia Shah Campus ID (FK) C2 C1 C1
Campus Name
Softwarica Islington The British College
Department
Department ID D1 D2 D3 Name Humanities Computing Maths Campus ID (FK) C1 C2 C2
The Solution
The solution is to adopt a different structure where we have a Campus having one or more Departments which in turn have one or more Staff.
Staff
1..*
1..* Department
Campus
The Solution
Campus
Campus ID
C1 C2 C3
Staff
Staff ID S1 S2 S3 Name Eric Hudson Sandra Smith Malia Shah Department ID (FK) D3 D1 D1
Campus Name
Softwarica Islington The British College
Department
Department ID D1 D2 D3 Name Humanities Computing Maths Campus ID (FK) C1 C2 C2
Presentation
Fan Traps Chasm Traps Pronunciation /kaz()m/
Fan Traps
Fan traps occur in a situation when a model represents relationship between entity types however a path between certain entity occurrences is ambiguous.
Staff
1..*
Campus
1..*
Department
In this model, it may be impossible to determine the department a staff belongs to.
1..* Department
Campus
Chasm Traps
Chasm Traps occur where there are relationships between entities, but one of the relationships is non-mandatory. A model suggests the existence of a relationship between entity types, but the pathway does not exist between certain entity occurrences. This connection traps is known as Chasm Traps.
http://db.grussell.org/section005.html
Branch
1...*
Staff
0...1
0...*
Property
Staff
Name Davinda Roberta Eddie Branch ID (FK) 1 1 2
1 Branch 1
1...* Staff
0...1
When a customer wants to reserve a particular model they can do so. This is recorded against a model rather than the car.
When a car of that model becomes available, it will be held for the customer. When they come in for it, a record is made on the reservation to say which car satisfied the reservation.
When a customer wants to reserve a particular model they can do so. This is recorded against a model rather than the car.
When a car of that model becomes available, it will be held for the customer. When they come in for it, a record is made on the reservation to say which car satisfied the reservation.
Car
0..N 1
Hire
Customer
1 1 0..N 0..N 0..N 1
Model
Reservation
Task
1. A customer records systems for a mail order beauty products company. A customer is assigned to one and only one geographical region. A customer may be interested in a number of different product lines. Any particular product line belongs to one product category that may contain many product lines.
2. Aboat is rented toa customer for a set periodof time. Any damage to the boat is recorded for that particular rental.
3. The shop needs to keep track of rentals. A member can rent films. A film can be rented by many members. A film can be rented by the same member more than once.
References
http://www.studytonight.com/dbms/er-diagram.php http://www.blackwasp.co.uk/SQLDerivedTables.aspx http://www2.cs.uregina.ca/~bernatja/crowsfoot.html
http://revj.sourceforge.net/traps.html
http://db.grussell.org/section005.html