DBMS R19 UNIT III-Part1
DBMS R19 UNIT III-Part1
Entities
Attributes
Relationships
A unary relationship is when both participants in the relationship are the same entity
A ternary relationship is when three entities participate in the relationship
One-to-Many (1:M)
Is where one occurrence in an entity relates to many occurrences in another entity.
For example, taking the employee and department entities shown on the previous page, an employee works
in one department but a department has many employees.
Therefore, there is a one-to-many relationship between department and employee.
Many-to-Many (M:N)
This is where many occurrences in an entity relate to many occurrences in another entity.
For example, an employee may work on several projects at the same time and a project has a team of many
employees.
Therefore, there is a many-to-many relationship between employee and project.
3. CONSTRAINTS
Constraints are categorized into 2 types
1) Key Constraints
2) Participation Constraints
Key Constraints :Keys are attributes or sets of attributes that uniquely identify an entity within its entity set.
These can be classified into 4 types as below.
1.Many to Many: An employee is allowed to work in different departments and a department is allowed to
have several employees.
2.One to Many: 1 employee can be associated with many departments, where as each department can be
associated with at most 1 employee as its manager.
3.Many to One:
Each employee works in at most 1 department.i.e, many employees can work in same department.
4.One to One:
Each employee can manage at most 1 department.
Participation Constraints :The participation constraint specifies whether the existence of an entity depends on
its being related to another entity via the relationship type.
A department has at most one manager. This requirement is an example of participation constraints. There
are 2 types of participation constraints, which are as below.
1.Total. 2.Partial.
Total: An entity set dependent on a relationship set and having one to many relationships is said to be ‘total’.
The participation of the entity set ‘departments’ in the relationship set ‘manages’ is said to be total.
Partial: A participation that is not total is said to be partial.
Example: Participation of the entity set ‘employees’ in ‘manages’ is partial, since not every employee gets to
manage a department.
In E-R diagram, the total participation is displayed as a ‘double line’ connecting the participating entity type to
the relationship, where as partial participation is represented by a single line. If the participation of an entity
set in a relationship set is total, then a thick line connects the two. The presence of an arrow indicates a key
constraint.
Weak Entities :Entity types can be classified into two categories: strong entity typesand weak entity types. A
strong entity type exists independent of other entity types, while a weak entity type depends on another
entity type. i.e.Entity types that do not have key attributes of their own are called as weak entity types. A
weak entity type always has a ‘total participation constraint’.
The dependent weak entity set and its relationship to employees is shown in the following diagram.
Linking them with a dark line indicates the total participation of dependents in policy.
To understand the fact that dependents is a weak entity and policy is its identifying relationship, we draw both
with dark lines. To indicate that ‘pname’ is a partial key for dependents, we underline it using a broken line.
4.REDUCTION TO RELATIONAL SCHEMAS:
We can represent a database that conforms to an E-R database schema by a col- lection of relation schemas.
For each entity set and for each relationship set in the database design, there is a unique relation schema to
which we assign the name of the corresponding entity set or relationship set.
.
Representation of Strong Entity Sets with Simple Attributes
Let E be a strong entity set with only simple descriptive attributes a1, a 2 ,..., an. We represent this entity by a
schema called E with n distinct attributes. Each tuple in a relation on this schema corresponds to one entity of
the entity set E.
For schemas derived from strong entity sets, the primary key of the entity set serves as the primary key of the
resulting schema. This follows directly from the fact that each tuple corresponds to a specific entity in the
entity set.
From the above fig This entity set has three attributes: ID, name, tot cred. We represent this entity set by a
schema called student with three attributes:
Note that since student ID is the primary key of the entity set, it is also the primary key of the relation
schema.
Continuing with our example, for the E-R diagram in Figure 7.15, all the strong entity sets, except time slot,
have only simple attributes. The schemas derived from these strong entity sets are:
classroom (building, room number, capacity) department (dept name,
building, budget) course (course id, title, credits)
instructor (ID, name, salary) student (ID, name, tot cred)
As you can see, both the instructor and student schemas are different from the schemas we have used in the
previous chapters (they do not contain the attribute dept name). We shall revisit this issue shortly.
Representation of Strong Entity Sets with Complex Attributes
When a strong entity set has nonsimple attributes, things are a bit more complex. We handle composite
attributes by creating a separate attribute for each of the component attributes; we do not create a
separate attribute for the composite attribute itself.
Multivalued attributes are treated differently from other attributes. We have seen that attributes in an
E-R diagram generally map directly into attributes for the appropriate relation schemas. Multivalued
attributes, however, are an exception; new relation schemas are created for these attributes, as we shall
see shortly.
complex attributes, without including the multivalued attribute, is thus:
instructor (ID, first name, middle name, last name, street number, street
name, apt number, city, state, zip code, date of birth)
We create a primary key of the relation schema consisting of all attributes of the schema. In the above
example, the primary key consists of both attributes of the relation instructor phone.
In addition, we create a foreign-key constraint on the relation schema created from the multivalued
attribute, with the attribute generated from the primary key of the entity set referencing the relation
generated from the entity set. In the above example, the foreign-key constraint on the instructor phone
relation would be that attribute ID references the instructor relation.
Representation of Weak Entity Sets
Let A be a weak entity set with attributes a1, a 2 ,..., am. Let B be the strong entity set on which A
depends. Let the primary key of B consist of attributes b1, b 2 ,..., bn. We represent the entity set A by a
relation schema called A with one attribute for each member of the set:
For schemas derived from a weak entity set, the combination of the pri- mary key of the strong entity
set and the discriminator of the weak entity set serves as the primary key of the schema. In addition to
creating a primary key, we also create a foreign-key constraint on the relation A, specifying that the
attributes b1, b2,..., bn reference the primary key of the relation B. The foreign- key constraint ensures that
for each tuple representing a weak entity, there is a corresponding tuple representing the corresponding
strong entity. Thus, we represent section by a schema with the following attributes:
The primary key consists of the primary key of the entity set course, along with the discriminator
of section, which is sec id, semester, and year. We also create a foreign-key constraint on the
section schema, with the attribute course id refer- encing the primary key of the course schema,
and the integrity constraint “on delete cascade”.7 Because of the “on delete cascade”
specification on the foreign key constraint, if a course entity is deleted, then so are all the
associated section entities.
• For a binary many-to-many relationship, the union of the primary-key at- tributes from the
participating entity sets becomes the primary key.
• For a binary one-to-one relationship set, the primary key of either entity set can be chosen as
the primary key. The choice can be made arbitrarily.
• For a binary many-to-one or one-to-many relationship set, the primary key of the entity set
on the “many” side of the relationship set serves as the primary key.