P2-DataModel-ER Model
P2-DataModel-ER Model
Basic It's used to describe a set of objects It's used to represent a collection of tables as well
known as entities, as well as the as the relationships between them.
relationships between them.
Used By This model is helpful for those people This model is mostly famous among programmers.
who don't have any knowledge about
how data is implemented.
Relationship It is easy to understand the relationship Compared to ER model, it is easier to derive the
between entities. relation between tables in the Relational model.
Entity: It is a “thing” or “object” in the real world that is distinguishable from other objects.
-In terms of DBMS, an entities are described by a set of attributes or table.
Example:
-Account is one entity and acc_no and balance are the attributes of account entity.
Entity set
It is a collection of entities of the same type which share similar properties.
For example:
- student: a group of students in a college.
- customer: All customers of a bank
Example
3. Derived attribute:
• The attribute that can be derived from the values of other related attributes or entities.
For example:
age-can be calculate from Date-of-birth(base attribute) and current date.
Relationship:
A relationship represents the association among the entities.
For example:
• ‘Enrolled in’ is a relationship type that exists between entity type Student and Course.
In ER diagram, relationship type is represented by a diamond and connecting the entities with lines.
A set of relationships of same type is known as relationship set.
In the above relationship set depicts S1 is enrolled in C2, S2 is enrolled in C1 and S3 is enrolled in C3
Degree of Relationship:
The number of different entity sets participating in a relationship set is called as degree of a
relationship set.
1. Unary Relationship –
When there is only ONE entity set participating in a relation, the relationship is called as unary
relationship. For example, one person is married to only one person.
2.Binary Relationship –
When there are TWO entities set participating in a relation, the relationship is called as binary relationship.
For example, Student is enrolled in Course.
3. n-ary Relationship –
When there are n entities set participating in a relation, the relationship is called as n-ary relationship.
Constraints:
Constraints are used for modeling limitations on the relations between entities.
There are two types of constraints on the Entity Relationship (ER) model −
Mapping cardinality or cardinality ratio.
Participation constraints.
1. Mapping Cardinality:
The number of times an entity of an entity set participates in a relationship set is known as cardinality.
Cardinality can be of different types:
One to one – When each entity in each entity set can take part only once in the relationship, the cardinality is
one to one.
Let us assume that a male can marry to one female and a female can marry to one male. So the relationship will be
one to one.
Many to one –
When entities in one entity set can take part only once in the relationship set and entities in other
entity set can take part more than once in the relationship set.
Many to many – When entities in all entity sets can take part more than once in the
relationship cardinality is many to many.
2. Participation Constraint:
It refers to whether an entity must participate in a relationship with another entity to exist
Total Participation – Each entity in the entity set must participate in the relationship.
-Total participation is shown by double line in ER diagram.
EX: If each student must enroll in a course, the participation of student will be total.
Partial Participation – The entity in the entity set may or may NOT participate in the relationship. If
some courses are not enrolled by any of the student, the participation of course will be partial.
The diagram depicts the ‘Enrolled in’ relationship set with Student Entity set having total participation
and Course Entity set having partial participation.
Keys in ER diagrams
A key/primary key is an attribute in ER diagrams whose values are distinct for each individual
entity in an entity set.
For example:
- for a student entity set Roll Number or Registration Number can be a key because these are unique for
each student entity.
Super Key
It is the attribute or set of attributes that can uniquely identify each entity in an entity set.
For Example:
• Customer_id of customer entity set.
• Combination of customer_id and customer_name of customer entity set but not customer_name.
Candidate Keys
It is the super key for which no proper subset is a super key. Such minimal super keys are called candidate
keys.
Extended E-R Features
These features are needed for the complex database.
Specialization
Generalization
Aggregation
Specialization
The process of designing sub groupings within an entity set is called specialization.
It’s a top-down approach.
In the E-R diagram specialization is represented by triangle components labeled ISA. The ISA relationship is
referred as superclass- subclass relationship.
Examples:
Generalization
It is the reverse process of specialization. It is a bottom-up approach.
It converts subclasses to superclasses.
This process combines a number of entity sets that share the same features into higher-level entity sets.
Aggregation
Aggregation allows to indicate that a relationship set participates in another relationship set.
The relation between two entities is treated as a single entity. In aggregation, relationship with its corresponding
entities is aggregated into a higher level entity.
Example:
customer
Company
Borrower
Loan
Examples: Company ER Model
Examples:University Database
• The university offers one or more programs.
• A program is made up of one or more courses.
• A student must enroll in a program.
• A student takes the courses that are part of her program.
• A program has a name, a program identifier, the total credit points required to graduate, and the year it commenced.
• A course has a name, a course identifier, a credit point value, and the year it commenced.
• Students have given names, a surname, a student identifier, a date of birth, and the year they first enrolled.
• When a student takes a course, the year and semester he attempted it are recorded. When he finishes the course, a grade
(such as A or B) and a mark (such as 60 percent) are recorded.
• Each course in a program is sequenced into a year (for example, year 1) and a semester (for example, semester 1).
Entity Sets and Attributes:
Program: Name, program_id, creditPoints, YearCommenced
Course(weak entity set): Name,course_id, creditPoints, YearCommenced
Student: GivenNames, Surname, Student_Id, Date_of_Birth,YearEnrolled
Relationship Sets :