Unit 2
Unit 2
UNIT-2
ENTITY RELATIONSHIP MODEL AND RELATIONAL DBMS
E-R DIAGRAM
Entity-Relationship (ER) Model is based on the notion of real-world entities and relationships among them.
While formulating real-world scenario into the database model, the ER Model creates entity set,
relationship set, general attributes and constraints.
A conceptual data model is a set of concepts that describes the structure of a database and the associated
retrieval of and update transactions on the database. The main purpose of developing a high-level data
model is to support a user’s perception of the data and to conceal the more technical aspects associated
with database design. Furthermore, a conceptual model is independent of the particular DBMS and
hardware platform that is used to implement the database.
An E-R Diagram (ERD) is a pictorial representation of an E-R model. ERD or data schema map or data
map is another means of capturing the data and their organization. The ERD captures the entities, their
attributes and the relationships between the entities. The major components of an ERD are entities,
attributes, relationships and cardinality of the association.
Entity
Entities can be characterized into two types:
Strong entity: A strong entity has a primary key attribute which uniquely identifies each entity.
Symbol of strong entity is same as an entity. It is represented by a rectangular box.
Strong Entity
Weak entity: A weak entity does not have a primary key attribute and depends on other entity
via a foreign key attribute. It is represented by a double rectangular box.
Weak Entity
ATTRIBUTES: Each entity has a set of properties. These properties of each entity are termed as attributes.
For example, a car entity would be described by attributes such as price, registration number, model
number, color etc. Attributes are indicated by ovals in an e-r diagram.
1
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
Attribute
A primary key attribute is depicted by an underline in the e-r diagram. An attribute can be characterized
into following types:
Simple attribute:- An attribute is classified as a simple attribute if it cannot be partitioned into
smaller components. For example, age and sex of a person. A simple attribute is represented by
an oval.
Composite attribute:- A composite attribute can be subdivided into smaller components which
further form attributes. For example, ‘name’ attribute of an entity “person” can be broken down
into first name and last name which further form attributes. Grouping of these related attributes
forms a composite attribute. ‘name is the composite attribute in this example.
Composite Attribute
Single valued attribute:- If an attribute of a particular entity represents single value for each
instance, then it is called a single-valued attribute. For example, Ramesh, Kamal and Suraj are the
instances of entity ‘student’ and each of them is issued a separate roll number. A single oval is
used to represent this attribute.
Multi valued attribute:– An attribute which can hold more than one value, it is then termed as
multi-valued attribute. For example, phone number of a person. Symbol of multi-valued attribute
is shown below,
2
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
The entities are represented by a rectangular box with the name of the entity in the box.
An attribute is shown as an ellipse attached to a relevant entity by a line and labeled with
the attribute name.
The entity name is written in uppercase where as the attribute name is written in
lowercase.
The primary keys are underlined
The attributes are connected using lines to the entities. IF the attribute is simple or single
valued a single line is used.
If the attribute is derived a dotted line is used.
If it is multi-valued then double lines are used.
If the attribute is composite. Its component attributes are shown as ellipses emanating
from the composite attributes.
RELATIONSHIPS
A relationship is an association between entities. Each relationship is identified so that its name
is descriptive of the relationship. Usually the relationship name is an active verb, but passive
verbs are also used. Relationships are represented by diamond shaped symbols with the
relationship name inside the diamond. The two sides of the diamond are connected to the
entities.
DEGREE
The degree of a relationship indicates the number of associated entities.
1. A unary relationship exists when an association is maintained within a single entity. For
example, consider the entity SUBJECT. Consider a situation where to take a particular
subject, you have to take another subject(like you should take Math to take the statistics).
This kind of relationship is called unary relationship and is represented as:
SUBJECT
requires
3
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
TEACHER
TEACHER
COURSE_MATERIAL
CONNECTIVITY
Relationships can be classified as one-to-one, one-to-many and many-to many. The term
connectivity is used to describe this relationship classification. The E-R diagram indicates the
relationship’s connectivity by placing a 1, M or N near the related entities as shown below:
1. One-to-One Relationship
1 1
MANAGER manages DEPARTMENT
4
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
2. One-to-Many Relationship
1 N
DEPARTMENT has EMPLOYEE
3. Many-to-Many Relationship
N N
EMPLOYEE joins COURSE
The training department of the company offers many COURSE(s) to the EMPLOYEE(s) as part of
the employee development program.
CARDINALITY
Cardinality expresses the specific number of the entity occurrences associated with one occurrence of
the related entity. The actual number of associated entities is governed by the business rules. The
cardinality is indicated by placing the appropriate numbers beside the entities.
1. One-to-Many Relationship
1 N
DEPARTMENT has EMPLOYEE
(1,1) (0,100)
2. Many-to-Many Relationship
N N
EMPLOYEE joins COURSE
(0,2) (0,10)
The company offers a maximum of ten COURSE(s), an EMPLOYEE may take up to two courses.
5
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
An entity type that is existence-dependent on some other entity is called a weak entity type or
existence-dependent and we represent them in double-lined rectangle. They are aka child,
dependent or subordinate entities.
An entity type that is not existence-dependent on some other entity type is called a strong entity
type. Aka parent, owner or dominant entity.
PARENT has
PARTICIPATION
There are two ways an entity can participate in a relationship- totally or partially. The participation is also
known as mandatory or optional. The participation is total(mandatory) if an entity’s existence requires
the existence of an associated entity in a particular relationship. The participation is said to be optional or
partial, if the occurrence of one entity does not require the occurrence of another corresponding entity
in a relationship.
N N
DEPARTMENT has EMPLOYEE
(1,2) (0,100)
In the example above DEPARTMENT can have a maximum of 100 employees or not at all, but there must
exist at least one DEPARTMENT. So, DEPARTMENT is a mandatory entity while EMPLOYEE is an optional
entity.
An optional entity is shown by drawing a small circle(O) on the side of the optional entity.
ISA Relationship
You can specify that one class is a subclass of another by creating an Isa relationship. An ISA relationship
implies that the subtype must have a matching super-type to exist. For example a CHILD entity should be
defined in the PERSON entity before it can exist as a CHILD.
sex
age address
PERSON
name profession
ISA
6
CHILD
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
The relationships are depicted in the data map using lines with added information to describe the
cardinality of the relationship like one-to-one, one-to-many, many-to-many, etc.
Entity Types :. A database usually contains groups of entities that are similar. For example, a company
employing hundreds of employees may want to store similar information concerning each of the
employees. These employee entities share the same attributes, but each entity has its own value(s) for
each attribute. An entity type defines a collection (or set) of entities that have the same attributes. Each
entity type in the database is described by its name and attributes.
Entity Sets: The collection of all entities of a particular entity type in the database at any point in time is
called an entity set; the entity set is usually referred to using the same name as the entity type. For
example, EMPLOYEE refers to both a type of entity as well as the current set of all employee entities in
the database.
7
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
KEYS
A DBMS key is an attribute or set of an attribute which helps you to identify a row(tuple) in a
relation(table). They allow you to find the relation between two tables. Keys help you uniquely identify a
row in a table by a combination of one or more columns in that table.
1. Super Key: A superkey is a group of single or multiple keys which identifies rows in a table. A
Super key may have additional attributes that are not needed for unique identification.
2. Candidate Key: A super key with no repeated attribute is called candidate key. The Primary key
should be selected from the candidate keys. Every table must have at least a single candidate key.
3. Primary Key: A column or group of columns in a table which helps us to uniquely identifies every
row in that table is called a primary key. This key can't be a duplicate. The same value can't appear
more than once in the table.
4. Alternate Key: All the Candidate keys which are not primary key are called an alternate key. It is
a candidate key which is currently not the primary key. However, A table may have single or
multiple choices for the primary key.
5. Foreign Key: A foreign key is a column which is added to create a relationship with another table.
Foreign keys help us to maintain data integrity and also allows navigation between two different
instances of an entity. Every relationship in the model needs to be supported by a foreign key.
6. Compound Key: Compound key has many fields which allow you to uniquely recognize a specific
record. It is possible that each column may be not unique by itself within the database. However,
when combined with the other column or columns the combination of composite keys become
unique.
7. Composite Key: A key which has multiple attributes to uniquely identify rows in a table is called a
composite key. The difference between compound and the composite key is that any part of the
compound key can be a foreign key, but the composite key may or maybe not a part of the foreign
key.
8. Surrogate Key: An artificial key which aims to uniquely identify each record is called a surrogate
key. These kind of key are unique because they are created when you don't have any natural
8
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
primary key. They do not lend any meaning to the data in the table. Surrogate key is usually an
integer.
Example:
Helps you to uniquely identify a record in the It is a field in the table that is the primary key of another
table. table.
Primary Key never accept null values. A foreign key may accept multiple null values.
Primary key is a clustered index and data in the A foreign key cannot automatically create an index,
DBMS table are physically organized in the clustered or non-clustered. However, you can manually
sequence of the clustered index. create an index on the foreign key.
You can have the single Primary key in a table. You can have multiple foreign keys in a table.
9
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
VALUE SET
Each simple attribute of an entity type is associated with a value set (or domain of values), which specifies
the set of values that may be assigned to that attribute for each individual entity. If the range of ages
allowed for employees is between 16 and 70, we can specify the value set of the Age attribute of
EMPLOYEE to be the set of integer numbers between 16 and 70. Similarly, we can specify the value set
for the Name attribute to be the set of strings of alphabetic characters separated by blank characters, and
so on. Value sets are not displayed in ER diagrams, and are typically specified using the basic data types
available in most programming languages, such as integer, string, Boolean, float, enumerated type, sub-
range, and so on.
We have discussed the Components and Symbols of ER-Diagram previously in this chapter spanned across
several topics, use this diagram as a reference.
10
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
COMPOSITE ENTITIES
A composite entity is also known as a “bridge” entity. This “bridge” is used to handle the many-to-many
relationships that the traditional entity could not handle. This entity lies between the two entities that are
of interest and this composite entity shares the primary keys from both the connecting tables. This
composite entity is also known as a “gerund” because it has the characteristics of an entity and a
relationship.
Consider the example of the entities AUTHOR and PUBLISHER. An Author can write for more than one
publisher. The publisher publishers the works of many different authors. So this is a many-to-many
relationship. But, this relationship cannot be transformed into relational tables as we require one-to-many
relationships.
We solve this by having a composite entity called WORK (which has among others, the primary keys of
the AUTHOR and PUBLISHER tables as its attributes).
11
UNIT-2 BCA402: DATABASE MANAGEMENT SYSTEM(DBMS)
Work_title
authorID publisherID
1 n n 1
AUTHOR WORK PUBLISHER
ENTITY LIST
The database model uses the entities and their attributes and relationships to construct a representation
of the real world system. The data model that results is in the form of an entity list or data map or both.
An entity list is a list or collection of the entities in the application and their attributes. For example, the
entity list of the book entity will be as we have seen below:
The entity list establishes the logical names to be used in the database design and use.5
12