DBMS Module2 Questions With Answers
DBMS Module2 Questions With Answers
Module 2
1. Define relation, domain, relation schema, attribute, tuple, degree, relational database,
relation or relation state
Each tuple in the relation can then be interpreted as a fact or a particular instance of the assertion.
Each relation can be viewed as a predicate and each tuple in that relation can be viewed as an
assertion for which that predicate is satisfied (has value true) for the combination of values in it.
Example:There exists a student having name Benjamin Bayer, having SSN 305-61-2435, having
age 19,etc
The salary of an employee should not exceed the salary of the employee’s supervisor and the
maximum number of hours an employee can work on all projects per week is 56. Such
constraints can be specified and enforced within the application programs that update the
database, or by using a general-purpose constraint specification language. Sometimes called as
Semantic Integrity constraint.
4. Define Super Key, Candidate key, Primary Key and Referential key (foreign key)
Super Key:
A super key is a set of one or more attributes that, taken collectively, uniquely identifies an entity
in an entity set.
In other words, a super key is a combination of attributes that uniquely identifies each tuple (row)
in a relation (table).
Candidate Key:
A candidate key is a minimal super key, meaning it is a super key with the fewest possible
attributes.
Each candidate key uniquely identifies tuples in a relation and no proper subset of a candidate key
has this property.
Primary Key:
The primary key is a candidate key that is selected by the database designer as the principal
means of identifying records within a table, (which is unique and not null)
It uniquely identifies each record in the table and ensures that there are no duplicate records.
Referential Key (Foreign Key):
A referential key, commonly known as a foreign key, is an attribute or set of attributes in one
relation whose values must match the primary key in another relation.
It establishes a relationship between two tables by referencing the primary key of one table from
another table.
The foreign key ensures referential integrity, meaning that the values in the referencing table must
exist in the referenced table or be null.
5. What are the basic operations that can change the states of relations in the database?
Explain how basic operations deals with constraint violations (or)
Briefly discuss different types of Update Operations on relational database. Show an
example of a violation of the referential and entity integrity in each of the update operation
There are three basic operations that can change the states of relations in the database: Insert,
Delete, and Update (or Modify).
Insert is used to insert one or more new tuples in a relation.
Delete is used to delete tuples.
Update (or Modify) is used to change the values of some attributes in existing tuples.
If an insertion violates one or more constraints, the default option is to reject the insertion.
Another option is to attempt to correct the reason for rejecting the insertion, but this is typically
not used for violations caused by Insert; rather, it is used more often in correcting violations for
Delete and Update.
The Delete Operation
The Delete operation can violate only referential integrity.
This occurs if the tuple being deleted is referenced by foreign keys from other tuples in the
database.
Step 1: For each regular (strong) entity type E in the ER schema, create a relation R that
includes all the simple attributes of E.
Step 2: For each weak entity type W in the ER schema with owner entity type E, create a relation
R, and include all simple attributes (or simple components of composite attributes) of W as
attributes. In addition, include as foreign key attributes of R the primary key attribute(s) of the
relation(s) that correspond to the owner entity type(s).
Step 4: For each regular binary 1:N relationship type R identify the relation (N) relation S. the
primary key of T as a foreign key of S. Simple attributes of R map to attributes of S.
Step 6: For each multi-valued attribute A, create a new relation R. This relation will include an
attribute corresponding to A, plus the primary key K of the parent relation (entity type or
relationship type) as a foreign key in R. The primary key of R is the combination of A and K.
The SELECT operation is used to choose a subset of the tuples from a relation that satisfies a
selection condition.
In general, the SELECT operation is denoted by
σ<selection condition>(R)
For example, to select the EMPLOYEE tuples whose department is 4, or those whose salary is
greater than$30,000
σDno=4(EMPLOYEE)
σSalary>30000(EMPLOYEE)
The PROJECT operation, selects certain columns from the table and discards the other columns.
π<attribute list>(R)
The general form of the PROJECT operation is
where (pi) is the symbol used to represent the PROJECT operation, and is the desired sublist of
attributes from the attributes of relation R.
For example, to list each employee’s first and last name and salary, we can use the PROJECT
operation as follows:
■ 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.
There are three types of joins: inner joins, natural joins, and outer joins.
Inner joins are classified into two types: Theta Join(for relational operators) and Equi Join(for
Equality).
There are three types of outer joins in DBMS: left outer join, right outer join, and full outer join.
Join operation = select operation + cartesian product operation
i. Theta join (R1 Ɵ R2) or (R1 <condition> R2):
If we join R1 and R2 other than the equal to condition then it is called theta join/ non-equi join.
ii. Natural join (R1 * R2) or(R1 <equal condition> R2):
If we join R1 and R2 on equal condition then it is called natural join or equi join. Generally, join
is referred to as natural join.
Natural join of R1 and R2 is –
we select those tuples from Cartesian product where the condition is equal
Outer join:
It is an extension of natural join to deal with missing values of relation.
Outer join is of three types, left outer join, right outer join and full outer join
R1 R2
Reg No Branch Section
1 CSE E
To illustrate JOIN, suppose that we want to retrieve the name of the manager of each department,
as follows:
DIVISION operation is applied to two relations R(Z) ÷ S(X), where the attributes of R are a
subset of the attributes of S; that is,
Example: To retrieve the names of employees who work on all the projects that ‘John Smith’
workson.
To express this query using the DIVISION operation, proceed as follows. First, retrieve the list of
project numbers that ‘John Smith’ works on in the intermediate relation SMITH_PNOS:
Dept. of CSE, Dr.TTIT, KGF 14
Next,createarelationthatincludesatuplewhenevertheemployeewhoseSsnisEssnworksonthe project
whose number is Pno in the intermediate relation SSN_PNOS: SSN_PNOS ← πEssn,
Pno(WORKS_ON)
Finally, apply the DIVISION operation to the two relations, which gives the desired employees’
Social Security numbers:
SSNS(Ssn) ← SSN_PNOS ÷ SMITH_PNOS
RESULT ← πFname, Lname(SSNS * EMPLOYEE)
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
superclassEMPLOYEEthatdistinguishesamongemployeeentitiesbasedonthejobtypeofeach employee.
Generalization
One can think of a reverse process of abstraction in which suppress the differences among several entity
types, identify their common features ,and generalize the m into a single superclass of which the original
entity types are special subclasses.
For example, consider the entity types CAR and TRUCK shown in below figure. Because they have several
common attributes, they can be generalized into the entity type VEHICLE, as shown in Figure.
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.