0% found this document useful (0 votes)
18 views

DBMS Module 2 SEE

The document discusses specialization and generalization in entity relationship diagrams. Specialization defines subclasses of an entity type based on distinguishing characteristics. Generalization identifies common features among entity types and generalizes them into a superclass. Examples of specialization and binary and ternary relationships are provided.

Uploaded by

pdacollege9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

DBMS Module 2 SEE

The document discusses specialization and generalization in entity relationship diagrams. Specialization defines subclasses of an entity type based on distinguishing characteristics. Generalization identifies common features among entity types and generalizes them into a superclass. Examples of specialization and binary and ternary relationships are provided.

Uploaded by

pdacollege9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Module 2 QB with Answers

1. Define Generalisation and Specialization. Illustrate how it is useful


with examples.
Ans:

 Specialization

Specialization is the process of defining a set of subclasses of an entity type; this entity type is
called the superclass of the specialization. The set of subclasses that forms a specialization is
defined on the basis of some distinguishing characteristic of the entities in the superclass.

For example, the set of subclasses {SECRETARY, ENGINEER, TECHNICIAN} is a specialization of


the superclass EMPLOYEE that distinguishes among employee entities based on the job type of
each employee entity.

We may have several specializations of the same entity type based on different distinguishing
characteristics. For example, another specialization of the EMPLOYEE entity type may yield the
set of subclasses {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}; this specialization distinguishes
among employees based on the method of pay. Figure 8.1shows how we represent a
specialization diagrammatically in an EER diagram.The subclasses that define a specialization
are attached by lines to a circle that represents the specialization, which is connected in turn
to the superclass. The subset symbol on each line connecting a subclass to the circle indicates
the direction of the superclass/subclass relationship.5 Attributes that apply only to entities of
a particular subclass—such as TypingSpeed of SECRETARY—are attached to the rectangle
representing that subclass. These are called specific attributes (or local attributes) of the
subclass.
In summary, the specialization process allows us to do the following:

 Define a set of subclasses of an entity type


 Establish additional specific attributes with each subclass
 Establish additional specific relationship types between each subclass and other entity
types or other subclasses.

 Generalization

We can think of a reverse process of abstraction in which we suppress the differences among
several entity types, identify their common features, and generalize them into a single
superclass of which the original entity types are special subclasses.

For example, consider the entity types CAR and TRUCK shown in Figure 8.3(a).Because they
have several common attributes, they can be generalized into the entity type VEHICLE, as
shown in Figure 8.3(b).Both CAR and TRUCK are now subclasses of the generalized superclass
VEHICLE. We use the term generalization to refer to the process of defining a generalized
entity type from the given entity types. Notice that the generalization process can be viewed
as being functionally the inverse of the specialization process. Hence, in Figure 8.3 we can view
{CAR, TRUCK} as a specialization of VEHICLE, rather than viewing VEHICLE as a generalization of
CAR and TRUCK. Similarly, in Figure 8.1 we can view EMPLOYEE as a generalization of
SECRETARY, TECHNICIAN,and ENGINEER.A diagrammatic notation to distinguish between
generalization and specialization is used in some design methodologies. An arrow pointing to
the generalized superclass represents a generalization, whereas arrows pointing to the
specialized subclasses represent a specialization. We will not use this notation because the
decision as to which process is followed in a particular situation is often subjective.
2. Explain ER diagram, naming conversion and design issues.
Ans:
Refer TB Page no 80 nd 81

3. Illustrate with example relationship types degree of higher than


two.
Ans:

A. Choosing between Binary and Ternary (or Higher-Degree) Relationships


 The ER diagram notation for a ternary relationship type is shown in below figure (a) ,
which displays the schema for the SUPPLY relationship type.
 The relationship set of SUPPLY is a set of relationship instances (s,j,p), where s is
SUPPLIER who is currently supplying PART p to a PROJECT j.
 In figure (b) shows an ER diagram for the three binary relationship types CAN_SUPPLY,
USES, and SUPPLIES.
 Suppose that CAN_SUPPLY, between SUPPLIER and PART, includes an instance (s,p)
whenever supplier s can supply part p (to any project).
 USES, and PROJECT and PART, includes an instance (j,p) whenever project j uses part p;
 SUPPLIES, between SUPPLIER and PROJECT, includes an instance (s,j) whenever supplier
s supplies some part to project j.nSome database design tools permit only binary
relationships
 In figure (b) shows an ER diagram for the three binary relationship types
CAN_SUPPLY,USES, and SUPPLIES.

Some database design tools permit only binary relationships

 A ternary relationship such as SUPPLY must be represented as weak entity type, with no
partial key and with three identifying relationships.
 The three participating entity types SUPPLIER,PART, and PROJECT are together the
owner entity types(see figure (c)).
 The ternary relationship type OFFERS in the above figure represents information on
instructors offering courses during particular semesters, hence it includes a relationship
instance (i,s,c) whenever INSTRUCTOR i offers COURSE c during SEMESTER s.

The three binary relationship types shown in above figure have the following meanings:

 CAN_TEACH relates a course to the instructors who can teach that course,
TAUGHT_DURING relates a semester to the instructors who taught some courses
offered during that semester, and OFFERED_DURING relates a semester to the courses
offered during that semester by any instructor.

B. Constraints on Ternary (or Higher-Degree) Relationships

Notations for specifying structural constraints on n-ary relationships

Cardinality ratio notation for binary relationships

 Her ,a 1,M, or N is specified on each participation arc( both M and N symbols stand for
many or any number).
 We place 1 on the SUPPLIER participation, and M,N on the PROJECT,PART participations
in below figure.
 This specifies the constraint that a particular (j,p) combination can appear at most once
in the relationship set because each such (PROJECT,PART) combination uniquely
determines a single supplier.
 Hence, any relationship instance (s,j,p) is uniquely identified in the relationship set by its
(j,p) combination, which makes (j,p) a key for the relationship set.
(min,max) notation for binary relationships

 A (min,max) on a participation here specifies that each entity is related to at least min
and at most max relationship instances in the relationship set.
 These constraints have no bearing on determining the key of an n-ary relationship,
where n>2, but specify a different type of constraint that places restrictions on how
many relationship instances each entity can participate in.
4. Explain the characteristics of relation.
Ans:

1. Ordering of Tuples in a Relation

A relation is defined as a set of tuples. Mathematically, elements of a set have no order


among them; hence, tuples in a relation do not have any particular order. Tuple ordering is not
part of a relation definition because a relation attempts to represent facts at a logical or
abstract level. Many tuple orders can be specified on the same relation.

2. Ordering of Values within a Tuple and an Alternative Definition of a Relation

The order of attributes and their values is not that important as long as the correspondence
between attributes and values is maintained. An alternative definition of a relation can be
given, making the ordering of values in a tuple unnecessary. In this definition A relation
schema R(A1, A2, ...,An), set of attributes and a relation state r(R) is a finite set of mappings r =
{t1, t2, ..., tm}, where each tuple ti is a mapping from R to D. According to this definition of
tuple as a mapping, a tuple can be considered as a set of (<attribute>, <value>) pairs, where
each pair gives the value of the mapping from an attribute Ai to a value vi from dom(Ai) .The
ordering of attributes is not important, because the attribute name appears with its value.

3. Values and NULLs in the Tuples

Each value in a tuple is atomic. NULL values are used to represent the values of attributes that
may be unknown or may not apply to a tuple. For example some STUDENT tuples have NULL
for their office phones because they do not have an office .Another student has a NULL for
home phone In general, we can have several meanings for NULL values, such as value
unknown, value exists but is not available, or attribute does not apply to this tuple (also known
as value undefined).

4. Interpretation (Meaning) of a Relation

The relation schema can be interpreted as a declaration or a type of assertion. For example,
the schema of the STUDENT relation of asserts that, in general, a student entity has a Name,
Ssn, Home_phone, Address, Office_phone, Age, and Gpa. Each tuple in the relation can then
be interpreted as a particular instance of the assertion.For example, the first tuple asserts the
fact that there is a STUDENT whose Name is Benjamin Bayer, Ssn is 305-61-2435, Age is 19,
and so on.
5. Explain Insert, delete and update operation.
Ans:
 The Insert Operation
 INSERT may violate any of the four types of constraints:
 Domain constraint:

If one of the attribute values provided for the new tuple is not of the specified attribute
domain.

 Key constraint:

If the value of a key attribute in the new tuple already exists in another tuple in the relation.

 Referential integrity:

If a foreign key value in the new tuple references a primary key value that does not exist in
the referenced relation.

 Entity integrity:

If the primary key value is null in the new tuple.

Example:-

 Operation:

Insert <‘Vinod’, ’S’, ‘Joseph’, NULL, ‘1986-04-05’, ‘#123, Bangalore’, F,

28000, NULL, 4> into EMPLOYEE

Result: Violates Entity IC , so it is rejected.

 Operation:

Insert <‘Alice’, ’J’, ‘Zelaya’, ‘999887777’, ‘1986-04-05’, ‘#334, Bangalore’, F,

28000, ‘98764321’, 4> into EMPLOYEE

Result: Violates Key IC , so it is rejected.

 Operation:

Insert <‘Cecilia’, ’F’, ‘Kolonsky’, ‘677678989’, ‘1986-04-05’, ‘#454, Bangalore’,


F, 28000, ‘99876436’, 7> into EMPLOYEE

Result: Violates Referential IC , so it is rejected.

 The Delete Operation


 DELETE may violate only referential integrity:

If the primary key value of the tuple being deleted is referenced from other tuples in the

database. Can be remedied by several actions: RESTRICT, CASCADE, SET NULL. RESTRICT
option: reject the deletion.CASCADE option: propagate deletion by deleting tuples that
reference the tuple that is deleted.SET NULL option: set the foreign keys of the referencing
tuples to NULL.One of the above options must be specified during database design for each
foreign key constraint.

 Example:
 Operation

Delete the WORKS_ON tuple with ESSN-’999887777’ and Pno=10.

Result: Acceptable. Deletes exactly one tuple

 Operation

Delete the EMPLOYEE tuple with SSN= ‘999887777’.

Result: Not Acceptable. Violates Referential IC.

 Operation

Delete the EMPLOYEE tuple with SSN= ‘333445555’.

Result: Not Acceptable. Violates Referential IC.

 The Update Operation


 UPDATE may violate domain constraint and NOT NULL constraint on an attribute being

modified. Any of the other constraints may also be violated, depending on the attribute being
updated:

 Updating the primary key (PK):


 Similar to a DELETE followed by an INSERT.
 Need to specify similar options to DELETE.
 Updating a foreign key (FK):
 May violate referential integrity.
 Updating an ordinary attribute (neither PK nor FK):
 Can only violate domain constraints.

 Operation

Update the salary of an EMPLOYEE tuple with SSN =‘999887777’ to 28000.

Result: Acceptable.

 Operation

Update the Dno of the EMPLOYEE tuple with SSN=‘999887777’ to 7.

Result: Violates Referential IC.

 Operation

Update the SSN of the EMPLOYEE tuple with SSN=‘999887777’ to ‘987654321’.

Result: Violates Primary key constraints.


6. Explain the following relational algebra operations with example.
(a) SELECT & PROJECT :
Ans:

The SELECT Operation

The SELECT Operation denoted by sigma is used to select a subset of the tuples from a relation
based on a selection condition. The selection condition acts as a filter that keeps only those
tuples that satisfy a qualifying condition. Alternatively, we can consider the SELECT operation
to restrict the tuples in a relation to only those tuples that satisfy the condition.

The SELECT operation can also be visualized as a horizontal partition of the relation into two
sets of tuples those tuples that satisfy the condition and are selected, and those tuples that do
not satisfy the condition and are discarded.

In general, the select operation is denoted by

<selection condition>(R)

where,

- the symbol is used to denote the select operator

- the selection condition is a Boolean (conditional) expression specified on the attributes of


relation R

- tuples that make the condition true are selected appear in the result of the operation

- tuples that make the condition false are filtered out discarded from the result of the
operation.

The Boolean expression specified in <selection condition> is made up of a number of clauses


of the form:

<attribute name> <comparison op> <constant value>

or

<attribute name> <comparison op> <attribute name>

where

<attribute name> is the name of an attribute of R,


<constant value> is a constant value from the attribute domain

Clauses can be connected by the standard Boolean operators and, or, and not to form a
general selection condition

Examples:

1. Select the EMPLOYEE tuples whose department number is 4.

DNO = 4 (EMPLOYEE).

The result of a SELECT operation can be determined as follows:

 The <selection condition> is applied independently to each individual tuple t in R


 If the condition evaluates to TRUE, then tuple t is selected.All the selected tuples appear
in the result of the SELECT operation
 The Boolean conditions AND, OR, and NOT have their normal interpretation, as follows:

- (cond1 AND cond2) is TRUE if both (cond1) and (cond2) are TRUE; otherwise,it is FALSE.

- (cond1 OR cond2) is TRUE if either (cond1) or (cond2) or both are TRUE; otherwise, it is
FALSE.

- (NOT cond) is TRUE if cond is FALSE; otherwise, it is FALSE.

 The fraction of tuples selected by a selection condition is referred to as the selectivity of


the condition.

The SELECT operation is commutative; that is,

<cond1> <cond2> <cond2> <cond1>(R))

Hence, a sequence of SELECTs can be applied in any order.we can always combine a cascade
(or sequence) of SELECT operations into a single SELECT operation with a conjunctive (AND)

condition; that is,

<cond1> <condn>(R <cond1> AND<cond2> AND ... AND <condn>(R)

In SQL, the SELECT condition is specified in the WHERE clause of a query.For example, the
following operation:

Dno=4 AND Salary>25000 (EMPLOYEE)

would to the following SQL query:


SELECT * FROM EMPLOYEE WHERE Dno=4 AND Salary>25000;

 The PROJECT Operation

The PROJECT operation denoted by selects certain columns from the table and discards the
other columns Used when we are interested in only certain attributes of a relation. The result
of the PROJECT operation can be visualized as a vertical partition of the relation into two
relations:

- one has the needed columns (attributes) and contains the result of the operation.

- the other contains the discarded columns.

The general form of the PROJECT operation is

<attribute list>(R)

where

(pi) - symbol used to represent the PROJECT operation,

<attribute list> - desired sublist of attributes from the attributes of relation R.

The result of the PROJECT operation has only the attributes specified in <attribute list> in the
same order as they appear in the list. Hence, its degree is equal to the number of attributes in
<attribute list>.

Example:

1. To list each employee's first and last name and salary we can use the PROJECT operation as
follows:

∏ Lname, Fname, Solary (EMPLOYEE)

If the attribute list includes only non key attributes of R, duplicate tuples are likely occur. The
result of the PROJECT operation is of distinct tuples, and hence a valid relation. This is known.
duplicate elimination. For example, consider the following PROJECT operation:

∏gender, Salary (EMPLOYEE)


The tuple <’F’,2500> appears only once in resulting relation even though this combination of
values appears twice in the EMPLOYEE relation.

The number of tuples in a relation resulting from a PROJECT operation is always less than or
equal to the number of tuples in R. Commutativity does not hold on PROJECT

∏ <list1> <list2>(R <list1>(R)

as long as <list2> contains the attributes in <list1>; otherwise, the left-hand side is an
incorrect expression.

In SQL, the PROJECT attribute list is specified in the SELECT clause of a query. For example, the

following operation:

∏ gender, Salary(EMPLOYEE) would correspond to the following SQL query:

SELECT DISTINCT gender, Salary FROM EMPLOYEE.


(b) UNION,INTERSECTION AND MINUS OPERATION
 UNION: The result of this operation, denoted by R S, is a relation that includes all tuples
that are either in R or in S or in both R and S. Duplicate tuples are eliminated.
 INTERSECTION: The result of this operation, denoted by R S, is a relation that includes all
tuples that are in both R and S.
 SET DIFFERENCE (or MINUS): The result of this operation, denoted by R S, is a relation
that includes all tuples that are in R but not in S.

Example: Consider the the following two relations: STUDENT & INSTRUCTOR.
Single relational algebra expression:

Ssn Dno=5 (EMPLOYEE) ) Super_ssn ( Dno=5 (EMPLOYEE))

UNION, INTERSECTION and SET DIFFERENCE are binary operations; that is, each is applied to
two sets (of tuples). When these operations are adapted to relational databases, the two
relations on which any of these three operations are applied must have the same type of
tuples; this condition has been called union compatibility or type compatibility.

Two relations R(A1, A2, ..., An) and S(B1, B2, ..., Bn) are said to be union compatible (or type
compatible) if they have the same degree n and if dom(Ai) = dom(Bi the two relations have the
same number of attributes and each corresponding pair of attributes has the same domain.

Both UNION and INTERSECTION are commutative operations; that is,

RUS = S U R and R ∩ S = S ∩ R

Both UNION and INTERSECTION can be treated as n-ary operations applicable to any number
of relations because both are also associative operations; that is,

R U (S U T) = (R U S) U T and (R∩ S∩ T = R∩ S∩ T )

The MINUS operation is not commutative; that is, in general,

R- S= S- R

INTERSECTION can be expressed in terms of union and set difference as follows:

In SQL, there are three operations UNION, INTERSECT, and EXCEPT that correspond to the

set operations.

(c) RENAME OPERATION


(d) DIVISION OPERATION
(e) CROSS PRODUCT
(f) JOIN & OUTER JOIN

Refer from TB

You might also like