VTU Exam Question Paper With Solution of 18CS53 Database Management System March-2021-Dr. Anand R
VTU Exam Question Paper With Solution of 18CS53 Database Management System March-2021-Dr. Anand R
VTU Exam Question Paper With Solution of 18CS53 Database Management System March-2021-Dr. Anand R
iii) Entity: Entity in DBMS can be a real-world object with an existence, For example, in a
College database, the entities can be Professor, Students, Courses, etc.
iv) Snapshot: Database snapshots are like a view of a database as it was at a certain
point in time. It is a read-only copy of the data and the state of the pages, which are
made possible using a pointer file called the sparse file. Snapshot is a recent copy
of the table from the database or a subset of rows/columns of a table. The SQL
statement that creates and subsequently maintains a snapshot normally reads data
from the database residing server. A snapshot is created on the destination system
with the create snapshot SQL command. The remote table is immediately defined
and populated from the master table.
These are used to dynamically replicate data between distributed databases. Two
types of snapshots are available.
1. Simple snapshots
2. Complex snapshots
Database users are categorized based up on their interaction with the data base.
For examples, Railway’s ticket booking users are naive users. Clerk in any
bank is a naive user because they don’t have any DBMS knowledge but they
still use the database and perform their given task.
3. System Analyst:
System Analyst is a user who analyzes the requirements of parametric end
users. They check whether all the requirements of end users are satisfied.
4. Sophisticated Users:
Sophisticated users can be engineers, scientists, business analyst, who are
familiar with the database. They can develop their own data base
applications according to their requirement. They don’t write the program
code but they interact the data base by writing SQL queries directly through
the query processor.
5. Data Base Designers:
Data Base Designers are the users who design the structure of data base
which includes tables, indexes, views, constraints, triggers, stored
procedures. He/she controls what data must be stored and how the data
items to be related.
6. Application Program:
Application Program are the back end programmers who writes the code for
the application programs. They are the computer professionals. These
programs could be written in Programming languages such as Visual Basic,
Developer, C, FORTRAN, COBOL etc.
7. Casual Users / Temporary Users :
Casual Users are the users who occasionally use/access the data base but
each time when they access the data base they require the new information,
for example, Middle or higher level manager.
In contrast with the File Based Data Management System, Dbms has numerous
benefits. We are putting light on some of the considerable benefits here–
1. Data Integrity
Data integrity means data is consistent and accurate in the database. It is essential as
there are multiple databases in DBMS. All these databases contain data which is
visible to multiple users. Therefore, it is essential to ensure that data is consistent and
correct in all databases for all users.
2. Data Security
Data security is a vital concept in a database. Only users authorized must be allowed
to access the database and their identity must be authenticated using username and
password. Unauthorized users shouldn’t be allowed to access the database under any
circumstances as it violets the integrity constraints.
A DBMS provides a better platform for data privacy thus helping companies to offer
an improved data security.
Due to the database management system, we have access to well managed and
synchronized form of data making it easy to handle. It also gives an integrated view
of how a particular organization is working and keeps track of how one segment of
the company affects another segment.
Data inconsistency occurs between files when various versions of the same data
appear in different places. Data consistency is ensured in the database; there is no
data redundancy. Besides, any database changes are immediately reflected by all
users, and there is no data inconsistency.
The database management system helps the users to produce quick answers to queries
making data accessing accurate and faster.
For any given dataset, dbms can help in solving insightful financial queries like:
1. What is the bonus given to every salesperson in the last two months?
Due to DBMS, we now have improved and managed data accessing because of which
we can generate better quality information which can hence make better decisions.
Better quality ultimately improves validity, accuracy and time it takes to read data. It
doesn’t guarantee data quality; it provides a framework to make it easy to enhance
data quality.
5. Simplicity
DBMS allows us to understand data better with a clear and simple logical view. With
dbms, many operations like deletion, insertion or creation of file or data, are easy to
implement.
DBMS automatically takes care of recovery and backup. The users are not required
to take periodical backup as this is taken care of by DBMS. Besides, it also restores
a database after a system failure or crash to prevent its previous condition.
The available data transform into helpful information with the help of combination
tools. It helps end users make better, informative and quick decisions that can make
the difference between success and failure in the global economy.
2.a i) Cardinality: 05
Cardinality is a relationship or joins between rows of 1 table to the rows of another
table. A number that represents, one instance of first entity (table) is related to how many
instances of the second entity, is known as cardinality.
ii)Weak Entity
Weak entity
A weak entity is an entity set that does not have sufficient attributes for Unique
Identification of its records
Simply a weak entity is nothing but an entity which does not have a primary key
attribute
It contains a partial key called as discriminator which helps in identifying a
group of entities from the entity set
Discriminator is represented by underlining with a dashed line
Representation
o A double rectangle is used for representing a weak entity set
o The double diamond symbol is used for representing the relationship
between a strong entity and weak entity which is known as identifying
relationship
o Double lines are used for presenting the connection with a weak entity
set with relationship
o In the ER diagram, we have two entities building and apartment
o Building is a strong entity because it has a primary key attribute called
building number which is capable of uniquely identifying all the flats
present in the apartment
o Unlike building, apartment is weak entity because it does not have any
primary key and door number here acts only as a discriminator
because door number cannot be used as a primary key, there might be
multiple flats in the building with the same door number or on different
floors.
v)Value Sets:
A value set is a uniquely identifiable set of valid concept representations, where any concept
representation can be tested to determine whether or not it is a member of the value set. A
value set is typically used to represent the possible values of a coded data element in an
information model.
1. Conceptual/Internal Mapping:
2. External/Conceptual Mapping:
1. Simple attribute:
An attribute which cannot be further subdivided into components is a simple
attribute.
2. Composite attribute:
An attribute which can be splitted into components is a composite attribute.
Example: The address can be further splitted into house number, street
number, city, state, country and pincode, the name can also be splitted into
first name middle name and last name.
3. Single-valued attribute:
The attribute which takes up only a single value for each entity instance is
single-valued attribute.
4. Multi-valued attribute:
The attribute which takes up more than a single value for each entity
instance is multi-valued attribute.
5. Derived attribute:
An attribute that can be derived from other attributes is derived attribute.
Examples:
STUDENT⋈STUDENT.ROLL_NO=EMPLOYEE.EMP_NOEMPLOYEE
STUDENT⋈STUDENT_SPORTS
3.c 10
Ans
(i) σ destination = “New Delhi” (flight)
ii) σ src = “Chennai” ^ dest = “New Delhi” (flight)
iii) Π fid (σ pid = 123 (booking) ⨝ σ dest = “Chennai” ^ fdate < 06/11/2020
(flight))
iv) (σ fdate = 01/12/2020 ^ time = 16:00 (flight)) ∩ (σ fdate = 02/12/2020 ^ time =
16:00 (flight))
v) Π passengers.pid, pname, pcity (σ pgender = “Male” (passengers ⨝ booking ⨝ agency))
For each weak entity type W in the ER schema with owner entity
type E, create a relation R & include all simple attributes (or simple
components of composite attributes) of W as attributes of R.
Also, include as foreign key attributes of R the primary key
attribute(s) of the relation(s) that correspond to the owner entity
type(s).
The primary key of R is the combination of the primary key(s) of the
owner(s) and the partial key of the weak entity type W, if any.
Example: Create the relation DEPENDENT in this step to correspond to the
weak entity type DEPENDENT.
Include the primary key SSN of the EMPLOYEE relation as a
foreign key attribute of DEPENDENT (renamed to ESSN).
The primary key of the DEPENDENT relation is the combination
{ESSN, DEPENDENT_NAME} because DEPENDENT_NAME is
the partial key of DEPENDENT.
For each regular binary 1:N relationship type R, identify the relation
S that represent the participating entity type at the N-side of the
relationship type.
Include as foreign key in S the primary key of the relation T that
represents the other entity type participating in R.
Include any simple attributes of the 1:N relation type as attributes of
S.
Example: 1:N relationship types WORKS_FOR, CONTROLS, and
SUPERVISION in the figure.
For WORKS_FOR we include the primary key DNUMBER of the
DEPARTMENT relation as foreign key in the EMPLOYEE relation
and call it DNO.
4.b 10
a. Find the names, street address, and cities of residence for all employees who
work for 'First Bank Corporation' and earn more than $10,000.
b. Find the names of all employees in the database who do not work for 'First
Bank Corporation'. Assume that all people work for exactly one company.
Select employee-name from works where company-name not in( 'First Bank Corporation');
c. Find the names of all employees in the database who earn more than every
employee of 'Small Bank Corporation'. Assume that all people work for at most
one company.
select employee-name from works where salary > all (select salary from works where
company-name = 'Small Bank Corporation')
d. Find the name of the company that has the smallest payroll
Select C.comany_name, min(salary) as “smallest payroll” from Employee E, Works
W, Company C where E.employee_name = W.employee_name and
W.company_name=C.company_name
Group by C.company_name ;
e. Find the names of all employees in the database who live in the same cities and on
the same streets as do their managers.
select p.employee-name from employee p, employee r, manages m where p.employee-
name = m.employee-name and m.manager-name = r.employee-name and p.street =
r.street and p.city = r.city
5.a Explain the Cursors and its properties in Embedded SQL with example: 05
A cursor is used to retrieve rows from a query that has multiple rows in its result
set. A cursor is a handle or an identifier for the SQL query and a position within
the result set.
Errors and warnings are returned in the SQLCA structure. See The SQL
Communication Area (SQLCA).
Example:
Create Table
The CREATE TABLE statement is used to create a new table in a database. In that
table, if you want to add multiple columns, use the below syntax.
Syntax
The column parameters specify the names of the columns of the table.
The data type parameter specifies the type of data the column can hold (e.g.
varchar, integer, date, etc.).
The LastName, FirstName, Address, and City columns are of type varchar and will
hold characters and the maximum length for these fields is 255 characters.
Syntax
The first way specifies both the column names and the values to be inserted.
If you are adding values for all the columns of the table, then no need to specify the
column names in the SQL query. However, make sure that the order of the values is
in the same order as the columns in the table.
Example
Insert value in a 1st way. The column names are used here
Here, column1, column2, ... are the field names of the table you want to select from
the data. If you want to select all the fields available in the table, use the following
syntax:
Example
Update Table
Syntax
1. UPDATE table_name
2. SET column1 = value1, column2 = value2, ...
3. WHERE condition;
Example
1. UPDATE Employee
2. SET FirstName= 'KS', City= 'Pune'
3. WHERE EmpId= 1;
If the above query is executed then for EmpId= 1, "Firstname" and "City" column
data will be updated.
It is the WHERE clause that determines how many records will be updated.
1. UPDATE Employee
2. SET City='Pune'
The DELETE statement is used to delete existing records in a table for a particular
Record.
Syntax
Example
Alter command is used to change the physical structure of a table such as adding or
removing columns, changing their data types, adding or removing business rules
etc.
Example
Example
Declaration_section
Executable_section
&&
;
IN parameter
OUT parameters
It is used to pass a parameter as output. Its value can be changed inside the stored
procedure, and the changed (new) value is passed back to the calling program. It is
noted that a procedure cannot access the OUT parameter's initial value when it
starts.
INOUT parameters
Type 4 drivers are the most common and are designed for a particular vendor's
database.
Type 1 JDBC drivers are used for testing JDBC applications against an ODBC
data source. Type 2 JDBC drivers require a native database API to be used. Both
Type 1 and Type 2 JDBC driver types mix a Java-based API with another API.
MySQL count() function returns the total number of values in the expression.
This function produces all rows or only some rows of the table based on a specified
condition, and its return type is BIGINT. It returns zero if it does not find any
matching rows. It can work with both numeric and non-numeric data types.
AVG() Function
MySQL AVG() function calculates the average of the values specified in the
column. Similar to the SUM() function, it also works with numeric data type only.
Suppose we want to get the average working hours of all employees in the table, we
need to use the AVG() function as shown in the following query:
MIN() Function
MySQL MIN() function returns the minimum (lowest) value of the specified
column. It also works with numeric data type only.
MAX() Function
MySQL MAX() function returns the maximum (highest) value of the specified
column. It also works with numeric data type only.
LAST() Function
This function returns the last value of the specified column. To get the last value
of the column, we must have to use the ORDER BY and LIMIT clause. It is
because the LAST() function only supports in MS Access.
GROUP_CONCAT() Function
Etc.
Anomalies
1- Update Anomaly: Let say we have 10 columns in a table out of which 2 are
called employee Name and employee address. Now if one employee changes it’s
location then we would have to update the table. But the problem is, if the table is
not normalized one employee can have multiple entries and while updating all of
those entries one of them might get missed.
2- Insertion Anomaly: Let’s say we have a table that has 4 columns. Student ID,
Student Name, Student Address and Student Grades. Now when a new student
enroll in school, even though first three attributes can be filled but 4th attribute will
have NULL value because he doesn't have any marks yet.
Normalization
Normalization is the process of organizing the data in the database.
Normalization is used to minimize the redundancy from a relation or set of
relations. It is also used to eliminate the undesirable characteristics like Insertion,
Update and Deletion Anomalies.
Normalization divides the larger table into the smaller table and links them using
relationship.
The normal form is used to reduce redundancy from the database table.
1NF:
Disallows
composite attributes
multivalued attributes
nested relations; attributes whose values for an individual tuple are non-atomic
Considered to be part of the definition of relation
2NF:
A relation schema R is in second normal form (2NF) if every non-prime
attribute A in R is fully functionally dependent on the primary key
R can be decomposed into 2NF relations via the process of 2NF normalization
3NF:
Definition:
Transitive functional dependency: a FD X -> Z that can be derived
from two FDs X -> Y and Y -> Z
Examples:
SSN -> DMGRSSN is a transitive FD
Since SSN -> DNUMBER and DNUMBER -> DMGRSSN hold
SSN -> ENAME is non-transitive
Since there is no set of attributes X where SSN -> X and X ->
ENAME
A relation schema R is in third normal form (3NF) if it is in 2NF and no non-
prime attribute A in R is transitively dependent on the primary key
R can be decomposed into 3NF relations via the process of 3NF normalization
NOTE:
In X -> Y and Y -> Z, with X as the primary key, we consider this a
problem only if Y is not a candidate key.
When Y is a candidate key, there is no problem with the transitive
dependency .
E.g., Consider EMP (SSN, Emp#, Salary ).
Here, SSN -> Emp# -> Salary and Emp# is a candidate key.
8.a 10
The functional dependency is a relationship that exists between two attributes. It typically
exists between the primary key and non-key attribute within a table.
X → Y
For example:
8.b 10
R1={ ACD}
R2={AB}
R3={BC}
R1∪R2∪R3=R=> {ACD}∪{AB}∪{BC}={ABCD}=R
A B C D
R1 * * *
R2 * *
R3 * *
A is common Attribute
A+=ABC
A is not a candidate key
R2 Join R3=>{ABC}
B is a common attribute
B+=BC
B is not a Candidate Key
ACID Properties:
ACID properties
Atomicity
A transaction is an atomic unit of processing; it is either performed in its entirety
or not performed at all.
Consistency preservation
A transaction is consistency preserving if its complete execution takes the
database from one consistent state to another
Isolation
The execution of a transaction should not be interfered with by any other
transactions executing concurrently
Durability
The changes applied to the database by a committed transaction must persist in
the database. These changes must not be lost because of any failure
Transaction states
• BEGIN_TRANSACTION: marks start of transaction
• READ or WRITE: two possible operations on the data
• END_TRANSACTION: marks the end of the read or write operations; start
checking whether everything went according to plan
• COMIT_TRANSACTION: signals successful end of transaction; changes can be
“committed” to DB
• Partially committed
• ROLLBACK (or ABORT): signals unsuccessful end of transaction, changes
applied to DB must be undone
9.c Need of concurrency control and recovery needed in DBMS: 10
Problems when two simple transactions run concurrently:
DBMS has a Concurrency Control sub-system to assure database remains in consistent state
despite concurrent execution of transactions
The DBMS must not permit some operations of a transaction T to be applied to the database
while other operations of T are not, because the whole transaction is a logical unit of
database processing. If a transaction fails after executing some of its operations but before
executing all of them, the operations already executed must be undone and have no lasting
effect. Types of Failures. Failures are generally classified as transaction, system, and media
failures. There are several possible reasons for a transaction to fail in the middle of
execution:
1. A computer failure (system crash). A hardware, software, or network error occurs in the
computer system during transaction execution. Hardware crashes are usually media
failures—for example, main memory failure.
2. A transaction or system error. Some operation in the transaction may cause it to fail, such
as integer overflow or division by zero. Transaction failure may also occur because of
erroneous parameter values or because of a logical programming error.3 Additionally, the
user may interrupt the transaction during its execution.
3. Local errors or exception conditions detected by the transaction. During transaction
execution, certain conditions may occur that necessitate cancellation of the transaction. For
example, data for the transaction may not be found. An exception condition, such as
insufficient account balance in a banking database, may cause a transaction, such as a fund
withdrawal, to be canceled. This exception could be programmed in the transaction itself,
and in such a case would not be considered as a transaction failure.
5. Disk failure. Some disk blocks may lose their data because of a read or write malfunction
or because of a disk read/write head crash. This may happen during a read or a write
operation of the transaction. 6. Physical problems and catastrophes. This refers to an endless
list of problems that includes power or air-conditioning failure, fire, theft, sabotage,
overwriting disks or tapes by mistake, and mounting of a wrong tape by the operator.
10.a The Deadlock and starvation problem occurs when 10
Deadlocks and Starvation
• 2PL can produce deadlocks
• Deadlock and starvation in 2PL
Deadlock occurs when each transaction T in a set of two or more transactions is
waiting for some item that is locked by some other transaction T’ in the set.
Deadlock prevention protocols
• Conservative 2PL, lock all needed items in advance
• Ordering all items in the database
Possible actions if a transaction is involved in a possible deadlock situation
• Block and wait
• Abort and restart
• Preempt and abort another transaction
Two schemes that prevent deadlock (Timestamp based)
Wait-die
An older transaction is allowed to wait on a younger transaction whereas a younger
transaction requesting an item from held by an older transaction is aborted and restarted
with the same timestamp
Wound-wait
A younger transaction is allowed to wait on an older transaction whereas an older
transaction requesting an item from held by a younger transaction preempts the younger
transaction by aborting it.
Starvation
A transaction cannot proceed for an infinite period of time while other transactions in the
system continue normally
• Unfair waiting scheme
• Victim selection
2PL Example