Dbms QP-15
Dbms QP-15
Dbms QP-15
SOLVED DEC-15
1 a) Write a note on various types of end users who use DBMS.
(08 M)
b) Explain the three level DBMS architecture, with a neat diagram. Why do we need
mappings between schema levels? Explain mapping in DBMS architecture.
(12 M)
Sol:
external/view level: includes a number of external schemas (or user views), each
of which describes part of the database that a particular category of users is interested in,
hiding rest of database. Can be described using either high-level or implementation data model.
(In practice, usually described using same model as is the conceptual schema.)
There is need for mappings between schema levels for visualization and schema matching. The
mappings between schema levels helps in the different types of transformation.
The processes of transforming requests and results between levels are called mappings.
These mappings may be time-consuming, so some DBMSs-especially those that are meant to
support small databases-do not support external views. Even in such systems, however, a certain
amount of mapping is necessary to transform requests between the conceptual and internal
levels.
By virtue of mappings between the levels:
external/conceptual mapping (providing logical data independence)
conceptual/internal mapping (providing physical data independence).
Data independence is the capacity to change the schema at one level of the architecture
without having to change the schema at the next higher level.
We distinguish between logical and physical data independence according to which two
adjacent levels are involved.
1. Logical data independence is the capacity to change the conceptual schema without having
to change external schemas or application programs. We may change the conceptual schema
to expand the database (by adding a record type or data item), to change constraints, or to
reduce the database (by removing a record type or data item). In the last case, external
schemas that refer only to the remaining data should not be affected.
2. Physical data independence is the capacity to change the internal schema without having
to change
the conceptual schema. Hence, the external schemas need not be changed as
well. Changes to the internal schema may be needed because some physical files had to be
reorganized-for example, by creating additional access structures-to improve the performance of
Prepared By: Prof. Gautam Dematti Page 3
1)
Entity: An entity represents some "thing" (in the miniworld) that is of interest to us,
i.e., about which we want to maintain some data. An entity could represent a physical
NATURAL JOIN: one of each pair of attributes with identical values is superfluous, a new
operation Called NATURAL JOIN-denoted by *-was created to get rid of the second
(superfluous) attribute in an EQUIJOIN conditions.
In the following example, we first rename the DNUMBER attribute of DEPARTMENT to
DNUM so that it has the same name as the DNUM attribute in PROJECT-and then apply
NATURAL JOIN:
c. Explain the SELECT and PROJECT operations in relational algebra with example.
(5M)
Sol:
SELECT :
The SELECT operation is used to select a subset of the tuples from a relation that satisfy a
selection condition. One can consider the SELECT operation to be a filter that keeps only those
tuples that satisfy a qualifying 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.
For example, to select the EMPLOYEE tuples whose department is 4, or those whose salary is
greater than $30,000, we can individually specify each of these two conditions with a SELECT
operation as follows:
PROJECT:
Prepared By: Prof. Gautam Dematti Page 8
EMPLOYEE)
(9M)
SELECT *
FROM room, hotel
WHERE room.price < 400 and hotel.name = RVN and room.type =
familyroom
ORDER BY price:
iii)
(5M)
Sol:
i) Drop Command: The DROP command can be used to drop named schema elements, such as
tables, domains, or constraints. One can also drop a schema.
For example, to remove the COMPANY database schema and all its tables, domains, and other
elements, the CASCADE option is used as follows:
DROP SCHEMA COMPANY CASCADE;
ii) Delete Command: The Delete operation can violate only referential integrity, if the tuple
being deleted is referenced by the foreign keys from other tuples in the database.
Delete the WORKS_ON tuple with ESSN = '999887777' and PNO = 10.
5 a) What a view? Explain how to create the view and how view can be dropped?
(8M)
Sol:
A view in SQL terminology is a single table that is derived from other tables. A view does
not necessarily exist in physical form; it is considered a virtual table, in contrast to base tables,
whose tuples are actually stored in the database.
In SQL, the command to specify a view is CREATE VIEW. The view is given a (virtual) table
name (or view name), a list of attribute names, and a query to specify the contents of the view.
Prepared By: Prof. Gautam Dematti Page 10
(12M)
Sol:
i) Embedded SQL:
Notice that the only embedded SQL commands are lines 1 and 7, which tell the
precompiler to take note of the C variable names between BEGIN DECLARE and END
DECLARE because they can be included in embedded SQL statements-as long as they are
preceded by a colon (:). Lines 2 through 5 are regular C program declarations. The C program
variables declared in lines 2 through 5 correspond to the attributes of the EMPLOYEE and
DEPARTMENT tables from the COMPANY database
0) int loop ;
1) EXEC SQL BEGIN DECLARE SECTION
2) varchar dname [16J. fname [16J. lname [16J, address [31J
3) char ssn [10J. bdate [l1J. sex [2J. mi ni t [2J ;
4) float salary, rai se ;
5) int dna. dnumber ;
6) int SQLCODE ; char SQLSTATE [6J
7) EXEC SQL END DECLARE SECTION ;
ii) Database stored procedure: it is sometimes useful to create database program modulesprocedures or functions-that are stored and executed by the DBMS at the database server. These
are historically known as database stored procedures, although they can be functions or
procedures.
Stored procedures are useful in the following circumstances:
If a database program is needed by several applications, it can be stored at the server and
invoked by any of the application programs. This reduces duplication of effort and improves
software modularity.
Executing a program at the server can reduce data transfer and hence communication cost
between the client and server in certain situations.
These procedures can enhance the modeling power provided by views by allowing more
complex types of derived data to be made available to the database users. In addition, they can be
Prepared By: Prof. Gautam Dematti Page 11
(6M)
Insertion anomalies.
Deletion anomalies.
Modification anomalies.
Insertion Anomalies
To insert a new employee tuple into EMP_DEPT, we must include either the attribute values for
that department that the employee works for, or nulls. It's difficult to insert a new department that
has no employee as yet in the EMP_DEPT relation. The only way to do this is to place null
values in the attributes for employee. This causes a problem because SSN is the primary key of
EMP_DEPT, and each tuple is supposed to represent an employee entity - not a department
entity.
Deletion Anomalies
If we delete from EMP_DEPT an employee tuple that happens to represent the last employee
working for a particular department, the information concerning that department is lost from the
database.
Modification Anomalies
In EMP_DEPT, if we change the value of one of the attributes of a particular department- say the
manager of department 5- we must update the tuples of all employees who work in that
department.
Guideline 2: Design the base relation schemas so that no insertion, deletion, or modification
anomalies occur. Reducing the null values in tuples. e.g., if 10% of employees have offices, it is
better to have a separate relation, EMP_OFFICE, rather than an attribute OFFICE_NUMBER in
EMPLOYEE.
Prepared By: Prof. Gautam Dematti Page 13
Guideline 4: Design relation schemas so that they can be naturally JOINed on primary keys or
foreign keys in a way that guarantees no spurious tuples are generated.
b) What is the need for Normalization? Explain the first, second, and third normal forms
with examples.
(14M)
Sol:
The purpose of normalization.
(10M)
Sol:
i) Inclusion dependencies: An inclusion dependency R.X < S.Y between two sets of attributes-X
of relation schema R, and Y of relation schema S-specifies the constraint that, at any specific
time when r is a relation state of Rand s a relation state of S, we must have
The ~ (subset) relationship does not necessarily have to be a proper subset.
Prepared By: Prof. Gautam Dematti Page 18
(10M)
Sol:
A transaction is an atomic unit of work that is either completed in its entirety or not done at all.
For recovery purposes, the system needs to keep track of when the transaction starts, terminates,
and commits or aborts
Transaction to transfer $50 from account A to account B:
1.
2.
3.
4.
5.
6.
Atomicity requirement
read(A)
A := A 50
write(A)
read(B)
B := B + 50
write(B)
o if the transaction fails after step 3 and before step 6, money will be lost leading
to an inconsistent database state
Failure could be due to software or hardware
o the system should ensure that updates of a partially executed transaction are not
reflected in the database
Durability requirement once the user has been notified that the transaction has
completed (i.e., the transfer of the $50 has taken place), the updates to the database by the
transaction must persist even if there are software or hardware failures.
Consistency requirement in above example:
the sum of A and B is unchanged by the execution of the transaction
In general, consistency requirements include
Explicitly specified integrity constraints such as primary keys and foreign
keys
Implicit integrity constraints
e.g. sum of balances of all accounts, minus sum of loan amounts
must equal value of cash-in-hand
o A transaction must see a consistent database.
o During transaction execution the database may be temporarily inconsistent.
o When the transaction completes successfully the database must be consistent
Erroneous transaction logic can lead to inconsistency
Isolation requirement if between steps 3 and 6, another transaction T2 is allowed to
access the partially updated database, it will see an inconsistent database (the sum
A+Bwillbelessthanitshouldbe).
T1
T2