13 Batch Mid Final Q Solve Database
13 Batch Mid Final Q Solve Database
1. Presentation Layer (UI): This is where users interact, often through a web browser
or app.
2. Application Layer (Logic): This middle layer processes commands, makes logical
decisions, and serves as a bridge between the user interface and the database.
3. Data Layer (Database): The back-end where data is stored and managed. This
layer is only accessible through the application layer.
This structure enhances security, allows scalability, and separates data management from
user interface concerns.
A serial schedule is a specific type of schedule where each transaction is completed one
after another, without overlapping. For example:
2. (b) Explain dirty read, non-repeatable read, phantom reads, and lost
updates using the table.
● Dirty Read: Reading uncommitted data from another transaction. For example, if
one transaction updates the price of Product1 to 6 but hasn't committed, another
transaction reads this uncommitted data.
● Non-Repeatable Read: When a transaction reads the same row twice and finds
different values due to another transaction's update. For instance, reading the price
of Product2 as 5 initially, but finding it changed to 6 in a subsequent read by another
transaction.
● Phantom Reads: When a transaction reads a set of rows that later changes due to
another transaction's insert or delete. If Transaction A retrieves all products, then
Transaction B adds Product3, A would see a "phantom" Product3 if it re-queries.
● Lost Updates: When two transactions update the same data simultaneously, and
one update is lost. If Transaction A sets the quantity of Product1 to 10, and
Transaction B also updates it to 12 without knowing A's change, one of the updates
could be lost.
3. (a) What are the ACID properties of a transaction? Draw the state
diagram of a transaction and describe each state.
Answer: ACID properties:
Transaction States:
Each transition occurs based on whether the transaction completes its tasks without errors
or needs to be reverted due to an issue.
4. (a) How do you identify conflicting instructions to determine conflict
serializability?
Answer: Conflicting instructions occur when two transactions access the same data and at
least one operation is a write. These conflicts can determine if a schedule can be rearranged
to achieve serializability, where results mimic a serial execution without conflicts.
● Conflict Equivalent: Two schedules are conflict equivalent if they have the same
conflicting operations in the same order.
● View Equivalent: Two schedules are view equivalent if they produce the same final
database state and the same results for all transactions.
For example, two schedules where Transaction A reads data before B writes it and both
result in the same end state are view equivalent.
Each transition depends on whether the transaction succeeds or encounters errors, ensuring
either full completion or complete rollback.
This setup ensures that transactions are managed smoothly across distributed sites.
● Tightly Coupled System: Systems are closely linked, sharing memory and CPU,
allowing for fast communication but with high interdependency.
● Loosely Coupled System: Components operate independently, connected over a
network, reducing interdependency and improving scalability.
Diagrams typically show tightly coupled systems with shared resources, while loosely
coupled systems have independent nodes linked via network connections.
For example:
3. (b) Using the given tables, design an optimized query to find the
names of all instructors in the Music department along with the titles of
the courses they teach.
Answer: Assume tables:
Optimized Query:
sql
SELECT Instructor.name, Course.title
FROM Instructor
JOIN Teaches ON Instructor.ID = Teaches.ID
JOIN Course ON Teaches.course_id = Course.course_id
WHERE Instructor.dept_name = 'Music';
This query finds music instructors and their course titles by joining relevant tables and
filtering by the "Music" department.
4. (b) Differentiate between cube and rollup operations using the 'sales'
relation schema (item-name, color, size, number).
Answer:
Design Issues:
5. (a) What is data mining? Explain a situation where data mining may be
useful.
Answer: Data mining is the process of discovering patterns in large datasets using
algorithms and statistical techniques.
Example Use Case: In retail, data mining can identify purchasing patterns to recommend
products to customers based on past purchases, enhancing sales and customer satisfaction.
5. (b) What is a cluster? Divide the individuals into two groups based on
their height and weight.
Answer: A cluster is a group of similar items. Here, we divide the students into two groups
based on height and weight.
Given data:
1.
2.
Grant SELECT privilege to Gonesh and Kopila on Reserves table with grant option.
sql
GRANT SELECT ON Reserves TO Gonesh, Kopila WITH GRANT OPTION;
3.
4.
6. (c) What is SQL injection? Give an example of SQL injection.
Answer: SQL Injection is a type of attack where malicious SQL code is inserted into a
query to manipulate or damage a database. It occurs when user inputs aren’t properly
sanitized.
sql
SELECT * FROM Users WHERE username = 'user' AND password = 'pass';
sql
SELECT * FROM Users WHERE username = 'user' OR '1'='1' AND password
= 'pass';
The OR '1'='1' part makes the condition true, allowing unauthorized access.
Locking-Based Concurrency Control Protocol: This protocol uses locks to control access
to data. Before a transaction can access data, it must acquire a lock. There are two main
types:
1. Growing Phase: The transaction acquires all necessary locks but cannot release
any.
2. Shrinking Phase: Once a transaction releases a lock, it cannot acquire any more
locks.
By dividing the process into these phases, 2PL prevents transactions from conflicting,
maintaining consistency across the database.