Unit III Dbms
Unit III Dbms
Syllabus
Data modeling using Entity-Relational Model: Data models, types of data models. E_R Model concepts: Entity,
Entity sets, Attributes, Types of attributes, key attribute and Domain of an attribute, Relationships between entities,
Relationship types, degree and cardinality ratio of a relationship, weak entity type, Notion of E-R diagram, Proper
naming of schema constructs
A Data model
- “a collection of concepts that can be used to describe the structure of a database”
- By structure of a database we mean the data types, relationships, and constraints that apply to the data.
- It provides necessary means to achieve data abstraction.
- Data abstraction generally refers to the suppression of details of data organization and storage, and the highlighting of the
essential features for an improved understanding of data
Representational / implementation data model: This data model lies between the high level and low level data
model which provides concepts that is understood by end user and also the way sata is organized within the
computer. It hides some storage techniques. The most common data models come under this data model are
Relational, network and hierarchical models.
Entity relationship model defines the conceptual view of database. An ER-diagram is a graphical representation
of organizations data storage requirements.
ER model on based on the facts of the real world
It is a collection of basic objects called entities and relationship among these entities.
The basic building blocks of ER diagrams are entity, attribute and relationship.
Entity
An entity is an object that exists and is distinguishable from other objects. In other words, the entity can be uniquely
identified. In the University database context, an individual student, faculty member, a class room, courses are
entities.
The examples of entities are:
- A particular person, for example Dr. A.P.J. Abdul Kalam is an entity.
1
DBMS UNIT-III Govt Arts and Science college, Karwar
Entity Type
An entity type or entity set is a collection of similar entities. Some examples of entity types are:
- All students in College, say STUDENT.
- All courses in College, say COURSE.
- All departments in College say DEPARTMENT.
An entity may belong to more than one entity type. For example, a staff working in a particular department can
pursue higher education as part-time. Hence the same person is a LECTURER at one instance and STUDENT at
another instance.
Relationship
A relationship is an association of entities where the association includes one entity from each participating entity
type whereas relationship type is a meaningful association between entity types.
The examples of relationship types are:
- Teaches is the relationship type between LECTURER and STUDENT.
- Buying is the relationship between VENDOR and CUSTOMER.
- Treatment is the relationship between DOCTOR and PATIENT.
Attributes
Attributes are properties of entity types. In other words, entities are described in a database by a set of attributes.
The following are example of attributes:
- Brand, cost, and weight are the attributes of CELLPHONE.
- Roll number, name, and grade are the attributes of STUDENT.
ER Diagram
Entity sets
Attributes
Relationship
Example of ER diagram
In the ER diagram the two entities are STUDENT and CLASS. Two simple attributes which are
associated with the STUDENT are Roll number and the name. The attributes associated with the
entity CLASS are Subject Name and Hall Number. The relationship between the two entities
STUDENT and CLASS is Attends.
2
DBMS UNIT-III Govt Arts and Science college, Karwar
Strong Entity: Strong entity is one whose existence does not depend on other entity.
Consider the example, student takes course. Here student is a strong entity. In this example, course is considered
as weak entity because, if there are no students to take a particular course, then that course cannot be offered. The
COURSE entity depends on the STUDENT entity.
Weak Entity:
Weak entity is one whose existence depends on other entity.
Entities are not of independent existence.
Each weak entity is associated with some entity of the owner entity set through a special relationship.
Weak entity set may not have a key attribute.
Consider the example, customer borrows loan. Here loan is a weak entity. For every loan, there should be at least
one customer. Here the entity loan depends on the entity customer hence loan is a weak entity.
Identifying relationship
Eg.2.
3
DBMS UNIT-III Govt Arts and Science college, Karwar
Attribute
Attribute is used to describe the properties of the entity. This attribute can be broadly classified based on value and
structure.
Attribute Classification
Single
Multivalue Derived Null
Value Attribute Attribute Attribute Simple Attribute Composite
Attribute
1. Simple attribute
These attributes have atomic or indivisible values and cannot be divided into smaller parts. The examples of
single value attribute are age of a person, Roll number of the student, Registration number of a car, etc.
Representation of single Value Attribute in ER Diagram -
2. Composite attribute
Composite attribute is one which can be further subdivided into simple attributes, having several
components in the value.
Representation if composite attribute in ER Diagram -
Example
4
DBMS UNIT-III Govt Arts and Science college, Karwar
1. Single-Valued Attributes: Single-valued attribute means, there is only one value associated with that attribute.
E.g. Roll no, Age, etc. Representation of single Value Attribute in ER Diagram is
2. Multi-Valued Attributes: In the case of multi-valued attribute, more than one value will be associated with that
attribute. E.g., Skills of an Employee, Phone No of a person etc. Representation of multi-valued in ER Diagram
is
3. Derived Attributes: The value of derived attribute can be derived from the values of other related attributes or
entities. The derived attribute may not be stored in the database but rather calculated using algorithm. Derived
attribute in ER Diagram is represented by
4. Null Attributes: In some cases, a particular entity may not have any applicable value for an attribute. For such
situation, a special value called null value is created. The situations where null value attributes can be used
where the value are not appropriate or not known.
5. Complex attribute: Comples attribute is a combination of composite and multivalued attributes. Complex
attributes are represented by { } and composite attributes are represented by ( ).
Example: Address phone attribute will hold both the address and phone number of any person.
{Address_phone ({Phone (Area_code,Phone_number)}, Address(Street_address(Number,Street,
Apartment_number), City, State, Zip))}
KEY ATTRIBUTES:
Key attribute represents the main characteristic of an Entity. It is used to represent Primary Key. Ellipse with
underlying lines represents Key Attribute.
Mathematically, an attribute A for an entity type E whose value set(domain) is V is defined as a function E to
the power set P(V) (set of all subsets) of V.
A: E-> P(V)
The value of an attribute A for entity e is A(e).
5
DBMS UNIT-III Govt Arts and Science college, Karwar
For a composite attribute A, the value set V is the Cartesian product of P(V1), P(V2),…P(Vn), where V1,V2…
Vn are the value sets of the simple component attributes that form
A:V = P(V1) x P(V2) x…..x P(Vn)
Example: V= {1,2} Power set P(V) = (∅,{1},{2},{1.2})
Relationship
A relationship is an association among at least two entities belonging to one or more entity sets. For example,
EMPLOYEE Sami works for IT DEPARTMENT. Relationships of the same type are grouped or types into a
relationship type or relationship set. Relationships are represented by diamonds.
Example:
Employee Works for Department
is-
Degree of relationship
The number of participating entities in a relationship defines the degree of the relationship.
The three most common relationships in ER models are Unary, Binary and Ternary.
1. Unary or Recursive Relationship: A Unary or recursive relationship occurs when an entity is related to itself.
The degree of Unary relationship is 1.
Example: Courses may be prerequisites for other courses.
Student may lead other students.
COURSES STUDENT
Require Lead
6
DBMS UNIT-III Govt Arts and Science college, Karwar
2. Binary Relatioship: When two entities are involed in a relation it is called binary relationship. The degree of
binary relation is 2.
3. Ternary Relationship: If three entities are involved in a relationship it is called ternary relationship. The
degree of ternary relation is 3.
4. n-ary Relationship :
When there are n entities set participating in a relation, the relationship is called as n-ary relationship
Cardinality Ratio
It is defined as the number of elements in one entity to the number of elements in the other entity which an be
participated in a relationship. The following are the types of relationship sets:
1. One to One
2. One to Many
3. Many to One
4. Many to Many
1. One to One Relationship (1:1) - When a single instance of an entity is associated with a single instance of
another entity then it is called one to one relationship. For example, a person has only one passport and a
passport is given to one person.
2. One to Many Relationship (1: M) - When a single instance of an entity is associated with more than one
instances of another entity then it is called one to many relationship. For example – a customer can place many
orders but a order cannot be placed by many customers.
3. Many to One Relationship (M: 1) - When more than one instances of an entity is associated with a single
instance of another entity then it is called many to one relationship. For example – many students can study in a
7
DBMS UNIT-III Govt Arts and Science college, Karwar
single college but a student cannot study in many colleges at the same time.
Participation Constraint
Participation constraint is a type of relationship constraint. It describes that whether the existence of an entity is
dependent on its relationship with another entity via the relationship type. There are two kinds of participation
constraints.
1. Total Participation – Each entity in the entity set must participate in the relationship. If each student must
enroll in a course, the participation of student will be total. Total participation is shown by double line in ER
diagram.
2. 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.
Every student in Student Entity set is participating in relationship but there exists a course C4 which is not taking
part in the relationship.
8
DBMS UNIT-III Govt Arts and Science college, Karwar
Notation of ER-Diagram
Symbol Meaning
Entity
Weak Entity
Relationship
Identifying relationship
Attribute
Key Attribute
Multi-valued Attribute
Composite Attribute
Derived Attribute
E1 R E2 Total participation of E2 in R
1 N
E1 R E2 Cardinality Ratio 1:N for E1:E2 in R
9
DBMS UNIT-III Govt Arts and Science college, Karwar
The database designers stated the following description of the “miniworld “– the part of the company to be
represented in the database.
The Company is organized into department. Each department has a unique name, a unique number and a
particular employee who manages the department. We keep track of the start date when that employee began
managing the department. A department may have several locations.
A department controls a number of projects, each of which has a unique name, a unique number and a single
location.
We store each employees name, social security number, address, salary, sex and birth date. An employee is
assigned to one department but may work on several projects, which are not necessarily controlled by the same
department. We keep track of the number of hours per week that an employee works on each project. We also
keep track of the direct supervisor of each employee.
We want to keep track of the dependents of each employee for insurance purposes. We keep each dependent’s
first name, sex, birth date and relationship to the employee.
10