Datamodels
Datamodels
1
E-R Model components
• Entity: An entity in ER Model is real world entity,
which has some properties called attributes.
Every attribute is defined by its set of values,
called domain or range. For example, in a school
database, a student is considered as an entity.
Student has various attributes like name, age and
class etc.
• An entity set is a collection of similar types of
entities. For example, Students set may contain
all the student of a school.
2
Attributes
• Attributes describe the properties of the entity of
which they are associated.
• A particular instance of an attribute is a value.
For example, "Ram" is one value of the attribute
Name.
• We can classify attributes as following:
¨ Simple
¨ Composite
¨ Single-valued
¨ Multi-valued
¨ Derived
3
• Attribute(s):
Attributes are the properties which define the entity type. For example,
Roll_No, Name, DOB, Age, Address, Mobile_No are the attributes
which defines entity type Student. In ER diagram, attribute is
represented by an oval.
• Key Attribute
The attribute which uniquely identifies each entity in the entity set is
called key attribute.For example, Roll_No will be unique for each
student. In ER diagram, key attribute is represented by an oval with
underlying lines.
4
• Multivalued Attribute –
An attribute consisting more than one value for a given entity. For example,
Phone_No (can be more than one for a given student). In ER diagram,
multivalued attribute is represented by double oval.
• Derived Attribute –
An attribute which can be derived from other attributes of the entity type is
known as derived attribute. e.g.; Age (can be derived from DOB). In ER
diagram, derived attribute is represented by dashed oval.
5
• CompositeAttribute
An attribute composed of many other attribute is called as composite
attribute. For example, Address attribute of student Entity type
consists of Street, City, State, and Country. In ER diagram, composite
attribute is represented by an oval comprising of ovals.
6
The complete entity type Student with its
attributes can be represented as:
7
E-R Model: Symbols and notations
8
E-R Model: Symbols and notations
9
E-R Model
• Relationship: The association among entities
is called relationship. For example, employee
entity has relation works_at with department.
• Relationships are mapped with entities in
various ways. Mapping cardinalities define
the number of association between two
entities.
10
Constraints
• Various types of constraints
are:
1. Mapping cardinalities
2. Participation constraints
3. Keys
11
Quiz
An ________ is a set of entities of the same type that
share the same properties, or attributes.
a) Entity set
b) Attribute set
c) Relation set
d) Entity model
12
Quiz
Entity is a _________
a) Object of relation
b) Present working model
c) Thing in real world
d) Model of relation
13
Keys
• The key is defined as the column or of the database
• attribute table.
They are used to establish and identify relation between tables.
• They also ensure that each record within a table can be uniquely identified
by combination of one or more fields within a table.
Types of Keys
1. Candidate key : An attribute (or set of attributes) that uniquely identifies a row.
Candidate Key is a super key with no repeated attributes.
14
Key
s
15
Keys
Super Key- An attribute (or combination of attributes) that
uniquely identifies each row in a table. It is a super set of candidate
key.
Example- Consider a student relation having attributes (RollNo,
Name, Class)
Here, RollNo is unique.
Therefore, the super keys will be
1. RollNo
2. RollNo, Name
3. RollNo, Class
4. RollNo, Name, Class
Types of Keys
3. Primary key : is the candidate key which is selected as the principal unique
identifier. It is a key that uniquely identify each record in the table. Cannot contain
null entries.
17
Types of Keys
5. Foreign Key: A foreign key is generally a primary key from one table that
appears as a field in another where the first table has a relationship to the
second.
In other words, if we had a table A with a primary key X that linked to a table B
where X was a field in B, then X would be a
foreign key in B.
18
Example
19
Difference between Primary and Candidate Key:
20
Quiz
a) Simple attribute
b) Composite attribute
c) Multivalued attribute
d) Derived attribute
21
Quiz
a) Single valued
b) Multi valued
c) Composite
d) Derived
22
Quiz
a) Phone_number
b) Name
c) Date_of_birth
d) All of the mentioned
23
Mapping Cardinalities
• Mappin cardinalit or cardinality ratios
g the
y , entities
of to
entity
express number associated via
be which
relationship
another can set a
• Mapping
cardinalities:
– one to one
– one to many
– many to one
– many to many
24
• One-to-one: one entity from entity set A can associated with at
be most one entity of entity set B and vice
versa.
25
• One-to-many: One entity from entity set A can be associated more than one entities
of entity set B but from entity set B one entity can be associated with at most one
entity.
26
• Many-to-one: More than one entities from entity set A
can be associated with at most one entity of entity set B
but one entity from entity set B can be associated with
more than one entity from entity set A.
27
• Many-to-many: one entity from A can be associated with more than one
entity from B and vice versa.
28
Quiz
a) One-to-many
b) One-to-one
c) Many-to-many
d) Many-to-one
29
Quiz
a) One-to-many
b) One-to-one
c) Many-to-many
d) Many-to-one
30
Participation Constraints
• The participation of an entity set E in a
relationship set R is said to be total if every
entity in E participates in at least one
relationship in R.
• If only some entities in E participate in
relationships in R, the participation is said to
be partial.
31
Example
33
Degree of Relationship Set
• 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.
34
Degree of Relationship Set
• Ternary Relationship – When there are three entities set
participating in a relation, the relationship is called as ternary
relationship.
35
Quiz
A). Entities
B). Attributes
C). Relationships
D). Descriptors
36
Quiz
A). Ellipse
B). Rectangle
C). Diamond
37
Strong and Weak entity sets
• The entity set which does not have sufficient attributes
to form a primary key is called a Weak entity set.
• The entity set which has the primary key is called as
Strong entity set.
• A member of a strong entity set is called dominant
entity and member of a weak entity set is called
subordinate entity.
• Weak entity does not have a primary key but we need
a mean to distinguish among other entities. The
discriminator of a weak entity set is a set of attributes
that allows this distinction to be made. Ex:
payment_number.
38
Example
39
Quiz
A). Strong
B). Weak
C). Dependent
D). Variant
40
Steps in designing E-R Diagram
• There are following steps:
– Identify the entities from the requirement
sheets
– Find relationships among those entities
– Identify the key attributes for every entity
– Identify other relevant attributes
– Draw complete E-R diagram with all
attributes including Primary key
– Review your results with your Business users
41
Example: University Management
System
42
Example: Hospital Management System
43
Example
44
E-R Diagram
45
Generalization and Specialization
Generalization
Generalization is a process of generalizing an entity which contains generalized
attributes or properties of generalized entities. The entity that is created will
contain the common features. Generalization is a Bottom up process.
We can have three sub entities as Car, Truck, Motorcycle and these three entities
can be generalized into one general super class as Vehicle.
46
Generalization and Specialization
Specialization
47