Professional Documents
Culture Documents
Set II
Question 1: Explain relationships with an example. Also show degree of
relationship for that example.
Employee e1, e3 and e6 work for department d1, e2 and e4 work for d2 and e5 and
e7 work for d3. Relationship type R is a set of all relationship instances.
WORKS_FOR
E1
DEPARTMENT
E2
EMPLOYEE
R1
D1
E3
R2
D2
E4
R3
D3
R4
E6 R5
Eete EE5
In the WORKS_FOR relationship type, the employee plays the role of employee or
worker and department plays the role of department or employer. However in
some cases the same entity type participates more than once in a relationship
type in different roles. Such relationship types are called recursive.
e.g. employee entity type participates twice in supervision once in the role of a
supervisor and once in the role of a supervisee.
Question 2: Explain the different operations of relational algebra with an
example each.
Select Operation: This operation is used to select the subset of the tuples from
a relation that satisfies a selection condition or search criteria. Mathematical
symbol σ [sigma] is used to denote the SELECT operator. The general syntax for
selection operation is shown below:
e.g. Select the employees who are working in department 10, and whose salary
is greater than Rs. 5000.
π<ATTRIBUTE LIST>(<relation>)
πNAME.SALARY (EMPLOYEE)
Relations R and S
R
ENo Name
1 Jyothi
2 Ganga
3 Girija
4 Ankitha
S
ENo Name
3 Girija
4 Ankitha
5 Tanvi
6 Manvi
Intersection (Π): The intersection operator selects the common tuples from
the two relations. The result of the operation R Π S is:
ENo Name
3 Girija
4 Ankitha
Union (U): The result of this operation is denoted by R U S, is a relation that
includes all tuples that are either in R or in S or in both. Duplicate tuples will not
appear in the output.
ENo Name
1 Jyothi
2 Ganga
3 Girija
4 Ankitha
5 Tanvi
6 Manvi
Difference: The result of difference (R-S) consists of all tuples in R but not in S.
ENo Name
1 Jyothi
2 Ganga
R
DNo Name
1 E&C
2 Computer Science
3 HRD
S
PNo PName
10 Networking
11 Payroll
Cartesian product of R and S can be written as:
Join Operation (x): The capability of retrieving multiple tables using a single
SQL statement can be accomplished using join operation. The join operation
denoted by x is used to combine two or more relations to retrieve useful
information.
Rx<join condition>S
For example, by joining employee and department relations, we can get the
name of the department in which the employee is working.
Solution: (a)
SQL Query – Select * from Std_Marks where Marks_CS > (Select Marks_CS from
Std_Marks where Student_Name = ‘Rashmi’)
ii. Let’s consider the following table (Std_Class) for the second
scenario:
Roll_No Student_Name Class
A101 Anand I
A102 Rashmi II
A103 Ram II
A104 Pankaj III
A105 Nita II
Binary Lock Function: Two operations, lock_item and unlock_item, are used
with binary locking. A transaction requests access to an item X by first issuing a
lock_item(X) operation. If LOCK(X) = 1, the transaction is forced to wait. If
LOCK(X) = 0, it is set to 1 and the transaction is allowed to access item X. When
the transaction is through using the item, it issues an unlock_item(X) operation,
which sets LOCK(X) to 0, so that X may be accessed by another transaction.
Hence, a binary lock enforces mutual- exclusion on the data item.
Lock_Item(D):
B: if LOCK(X) = 0 (“item is unlocked”)
Then LOCK(X) 1 (“lock the item”)
else begin
wait (until lock(X) = 0 and the lock manager wakes up the
transaction);
goto B
end;
unlock_item(X):
LOCK(X) 0; (“unlock the item”)