DBMS-DEC-19 Solved STRANGER
DBMS-DEC-19 Solved STRANGER
Q.NO QUESTION
MARKS
Q.1 a) Explain the difference between two-tier and three-tier architectures. Which is better
suited for Web applications? Why?
ANSNWER:
Two-tier and three-tier architectures are both designs for distributing application logic,
but they differ in their structure and functionalities.
Two-Tier Architecture:
• In a two-tier architecture, there are two main layers: the client or user interface
layer and the database server layer.
• The client layer is responsible for the presentation of the application and
interacts directly with the database layer.
• All the business logic is typically embedded in the client application, making it
responsible for both the presentation and the data access logic.
• It's simpler in design but can become cumbersome when dealing with a large
number of users or when modifications in the logic need to be implemented.
Three-Tier Architecture:
• A three-tier architecture adds an additional layer between the client and the
6
server layers, introducing the middle or application server layer.
• The three layers are the presentation layer (client), the application server layer,
and the data storage layer (database server).
• The presentation layer handles the user interface, the application server layer
manages the application logic and processing, and the data storage layer deals
with storing and retrieving data.
• This architecture separates concerns more distinctly, making it easier to scale and
maintain. It also allows for more flexibility and scalability as each layer can be
scaled independently.
For web applications, the three-tier architecture is generally more suitable for several
reasons:
While both architectures have their merits, three-tier architectures tend to be more
adaptable, scalable, and maintainable, making them the preferred choice for most
modern web applications.
b) Construct an E-R diagram for a car insurance company whose customers own one or
more cars each. Each car has associated with it zero to any number of recorded
accidents. Each insurance policy covers one or more cars, and has one or more premium
payments associated with it. Each payment is for a particular period of time, and has an
associated due date, and the date when the payment was received.
ANSWER:
Entities:
1. Customer
2. Car
3. Accident
4. Insurance Policy
5. Premium Payment 6
Attributes:
• Insurance Policy: PolicyID, Coverage Details, Start Date, End Date, etc.
Relationships:
1. Customer owns Car (1 to many): A customer can own one or more cars. (1
customer to many cars)
2. Car recorded in Accident (0 to many): A car can have zero to many recorded
accidents.
3. Insurance Policy covers Car (1 to many): An insurance policy covers one or more
cars. (1 policy to many cars)
4. Insurance Policy has Premium Payment (1 to many): An insurance policy has one
or more premium payments associated with it. (1 policy to many payments)
5. Premium Payment has Payment Period (1 to 1): Each payment is for a particular
period.
DESCRIPTION
INSURANCE POLICY
POLICY ID
START DATE
END DATE
COVERAGE
PREMIUM PAYMENT
PAYMENT ID
AMOUNT
DUE DATE
RECIVED DATE
This diagram depicts the relationships between entities in a car insurance system. Each
entity has its attributes, and the relationships between them are described through the
cardinality (how many of each entity are related to another entity)
ANSWER:
the SQL statements to perform the requested operations:
This SQL statement will add a new record to the `Student` table with the specified values
for name, student number, class, and major.
6
**(2) Change the credit hours of the course 'Data Science' to 4:
```
UPDATE Course
SET credit_hours = 4
WHERE c-name = 'Data Science';
```
This SQL statement will update the `credit_hours` column in the `Course` table where the
course name is 'Data Science', setting the credit hours to 4.
(3) Delete the record for the student whose name is 'Smith' and whose student number is
17:
```
DELETE FROM Student
WHERE name = 'Smith' AND s_no = 17;
```
This SQL statement will delete the record from the `Student` table where the name is
'Smith' and the student number is 17.
Q.3 a) Compute the closure of the following set F of functional dependencies for relation
schema
r(A,B,C,D,E).
A-> BC
CD->E
B-> D
E->A
ANSWER :
To compute the closure of the functional dependencies set F for relation schema
r(A,B,C,D,E), we'll use Armstrong's axioms and transitive rule until no new attributes can
be added.
Let's start computing the closure of attributes for each attribute and see if we can find
the candidate keys.
1. A+: 6
A+ contains A and any other attributes it can determine transitively.
- A+ = A
2. B+:
B+contains B and any other attributes it can determine transitively.
- B+ = BD
- Using B ->D and then D ->E from CD ->E (transitive), we get B+ = BDE
3. C+:
C+ contains C and any other attributes it can determine transitively.
- C+ = C (No additional attributes can be determined from C
4. D+:
D+ contains D and any other attributes it can determine transitively.
- D+ = D (No additional attributes can be determined from D
**5. E+ :
E+ contains E and any other attributes it can determine transitively.
- E+ = EA (Using E->A)
- Then, E+ = EAB (Using A -> BC and then B -> D)
Both AB and AE contain all the attributes A, B, C, D, E and are irreducible (i.e., removing
any attribute from them would result in a set that doesn't cover all attributes). Hence,
both AB and AE are candidate keys for relation schema r(A,B,C,D,E).
b) Illustrating the concept of fully functional dependency, explain 2NF with example.
ANSWER:
Fully functional dependency and 2NF (Second Normal Form) are closely related concepts
in database normalization.
For example, consider a table `Employees` with columns `EmployeeID`, `ProjectID`, and
`ProjectName`, where `EmployeeID` is the primary key.
2NF deals with removing partial dependencies in a relation by ensuring that all non-prime
attributes are fully functionally dependent on the entire primary key.
In this table:
- `(EmployeeID, ProjectID)` is the composite primary key.
- `ProjectName` is functionally dependent on `ProjectID` (and not on the entire primary
key) because for each `ProjectID`, `ProjectName` remains the same regardless of the
`EmployeeID`.
- `EmployeeName` is functionally dependent on `EmployeeID` but not on the entire
primary key.
EmployeeID ProjectID
1 101
1 102
2 101
Now, `ProjectName` is only in the `Projects` table, and `EmployeeName` is only in the
`Employees` table. This arrangement ensures that all non-prime attributes are fully
functionally dependent on the primary key in their respective tables, satisfying 2NF.
Q.4 a) Let relations r1 (A, B,C) and r2 (C,D,E) have the following properties: r1 has 20,000 tuples,
r2 has 45,000 tuples, 25 tuples of r1 fit on one block, and 30 tuples of r2 fit on one block.
Estimate the number of blocks transfers and seeks required, using each of the following
join strategies for r1∞ r2: (r1 Natural Join r2)
1. Nested-loop join.
ANSWER:
To estimate the number of block transfers and seeks required for performing the join 6
operation r1 ∞ r2 (where r1 is the natural join with r2) using different join strategies,
we'll consider the properties of the relations and the join algorithms.
Given:
- r1has 20,000 tuples, and 25 tuples fit in one block.
- r2 has 45,000 tuples, and 30 tuples fit in one block.
- **Number of seeks:**
- Each block of r1 will need to be read multiple times for each block of r2.
- Seeks required will be significant due to repeated scans of r1 for each block of r2.
Block nested-loop join involves reading blocks of one relation and performing nested-
loop joins with blocks of the other relation.
- **Number of seeks:
- The block nested-loop join doesn't reduce the number of seeks compared to the
nested-loop join, as it still requires multiple scans of blocks for each block of the other
relation.
Both the nested-loop join and block nested-loop join strategies result in the same
number of block transfers and seek operations for the given relations r1 and r2 due to
the nature of these join algorithms, where one relation is scanned multiple times for each
block of the other relation.
b) Explain Query processing? Explain various steps in query processing with the help of
neat sketch.
ANSWER: 6
• Parsing: The query is checked for syntax errors and parsed into a parse
tree or syntax tree.
2. Optimization:
3. Query Execution:
Assume that the tree is initially empty and values are added in ascending order.
Construct
6
B+ tree for the cases where the number of pointers that will fit in one node is as follows:
i. Four
ii. Six
ANSWER:
constructing B+ trees for the given set of key values, assuming the maximum number of
pointers that will fit in one node is four and six.
B+ Tree with Four Pointers Per Node:
Step 1: Creating the B+ tree with four pointers per node:
1. Start with an empty root.
2. Add keys sequentially: 2, 3, 5, 7, 11, 17, 19, 23, 29, 31.
The B+ tree would look like this:
Explanation:
• In both cases, the B+ tree maintains the keys in sorted order.
• With four pointers per node, the tree has more levels compared to the tree with
six pointers per node.
• A larger number of pointers per node results in a shallower tree and potentially
faster search times but requires more keys to fill a node before a split occurs.
• The structure and organization of the B+ tree change based on the maximum
number of pointers allowed in each node, affecting the tree's height and fanout
at each level.
b) Define ordered indices. Differentiate between Dense and sparse indices with suitable
example.
ANSWER:
Ordered indices are data structures used in databases to improve the efficiency of
searching, accessing, and retrieving data. They are based on a sorted ordering of key
6
values and enable faster lookup of records based on those keys.
Dense Indices:
Definition: Dense indices contain an entry for every search key value in the database.
• Example: Consider a simple scenario with a student database where the primary
key is the student ID. In a dense index, there would be an entry for every student
ID in the index. If a student with ID 101, 102, 103, and so on exists, the index will
have entries for each of these IDs.
• Characteristics:
• Require more storage space as they store an entry for every key value.
• Generally quicker for searching since they directly point to the location of
the record in the data file.
• Efficient for equality searches but may not be suitable for range queries.
Sparse Indices:
Definition: Sparse indices do not contain entries for every possible search key value.
• Example: Continuing with the student database, if the IDs are sparse and not all
values exist (e.g., student IDs 101, 103, 107 exist, but 102, 104, 105 are missing),
a sparse index will only have entries for the existing IDs. So, it will contain entries
for 101, 103, and 107 but not for 102, 104, and 105.
• Characteristics:
• Occupy less space as they only store entries for existing key values.
• Slower for direct searches since they may not directly point to the
location of the record; they might need to traverse other entries to
locate the desired record.
• Can be advantageous for range queries because they store fewer entries,
and scanning fewer index entries might be quicker for range operations.
Difference between Dense and Sparse Indices:
• Density of Entries:
• Dense indices have an entry for every key value, while sparse indices only
have entries for existing key values.
• Storage Space:
• Dense indices require more storage space as they contain entries for
every key value, whereas sparse indices occupy less space as they only
store entries for existing key values.
• Search Efficiency:
• Dense indices are generally faster for direct searches since they directly
point to the record's location.
• Sparse indices might be slower for direct searches as they may require
traversing more entries to locate the desired record.
The choice between using a dense or sparse index depends on the nature of the data, the
query patterns, and the trade-offs between storage space and search efficiency.
A schedule in database transactions refers to the order in which various transactions are
executed. A schedule is considered view serializable if it produces the same results as
some serial execution of the transactions.
• View Serializability: It ensures that the final result (state of the database) of
concurrent execution of multiple transactions should be equivalent to the result
obtained when the transactions are executed serially, one after another.