0% found this document useful (0 votes)
19 views9 pages

13 Batch Mid Final Q Solve Database

Uploaded by

techknoweasy101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views9 pages

13 Batch Mid Final Q Solve Database

Uploaded by

techknoweasy101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

(a) Define database architecture with an explanation of a 3-tier


architecture.
Answer: A 3-tier database architecture is a setup where the system is divided into three
layers:

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.

1. (b) What is a transaction? Explain the concurrent execution of


transactions.
Answer: A transaction is a sequence of database operations that are treated as a single
unit, which either fully completes or entirely fails (rollback). Each transaction must satisfy the
ACID properties (Atomicity, Consistency, Isolation, Durability).

Concurrent execution of transactions means multiple transactions are executed at the


same time. This can improve performance by maximizing resource usage, but it also
requires proper management to avoid issues like data inconsistency or interference between
transactions.

2. (a) With an example, define schedule and serial schedule.


Answer: A schedule is a sequence in which operations from different transactions are
interleaved (run together) or ordered.

A serial schedule is a specific type of schedule where each transaction is completed one
after another, without overlapping. For example:

● If we have Transaction A and Transaction B, in a serial schedule, all operations of A


would complete before B starts, ensuring no interference.

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:

1. Atomicity: Each transaction is all-or-nothing.


2. Consistency: Ensures the database stays in a valid state.
3. Isolation: Transactions do not interfere with each other.
4. Durability: Once a transaction commits, changes are permanent.

Transaction States:

1. Active: Transaction is running.


2. Partially Committed: All operations are done, but changes aren't permanent.
3. Committed: Changes are finalized in the database.
4. Failed: Transaction can't proceed and needs to be rolled back.
5. Aborted: Rolled back to the initial state before the transaction.

3. (b) During its execution, a transaction passes through several states


until it commits or aborts. List all possible sequences of states through
which a transaction may pass. Explain why each state transition may
occur.
Answer: Possible state sequences:

1. Active → Partially Committed → Committed: Normal successful


transaction.
2. Active → Partially Committed → Aborted: If an error occurs after the
transaction is completed but before commit.
3. Active → Failed → Aborted: Transaction encounters an error during execution.

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.

4. (b) What do you understand by conflict equivalent and view equivalent


schedules? Explain with an example.
Answer:

● 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.

4. (c) What are the conditions to determine view equivalence?


Answer: Conditions for view equivalence:

1. Both schedules must produce the same final state.


2. Read operations must read the same values in both schedules.
3. Each initial read in both schedules must match, and the order of writes should be the
same.

Final Question Solved


1. (a) What are the ACID properties of a transaction? Why might
database-system implementers pay more attention to the ACID
properties than file-system implementers?
Answer: The ACID properties ensure reliable transactions in databases:

1. Atomicity: The transaction is all-or-nothing.


2. Consistency: Transactions move the database from one valid state to another.
3. Isolation: Transactions don’t interfere with each other.
4. Durability: Once completed, changes are permanent.

Database-system implementers focus on ACID to maintain data integrity, especially with


multiple users accessing data concurrently, which is less common in file systems.
1. (b) List all possible sequences of states through which a transaction
may pass. Explain why each state transition may occur.
Answer: Possible transaction state sequences:

1. Active → Partially Committed → Committed: Normal sequence for a


successful transaction.
2. Active → Partially Committed → Aborted: If a problem occurs after
completion but before the commit.
3. Active → Failed → Aborted: If an error occurs during execution, leading to a
rollback.

Each transition depends on whether the transaction succeeds or encounters errors, ensuring
either full completion or complete rollback.

2. (a) Describe a model for Transaction Management System in DDBMS.


Write down the responsibilities of Transaction Manager and Coordinator.
Answer: In a Distributed Database Management System (DDBMS), a transaction
management model ensures transactions are handled across different locations.

● Transaction Manager: Manages local transactions, ensures ACID properties locally,


and communicates with the Coordinator.
● Coordinator: Oversees the transaction across all sites, ensuring global consistency,
and commits or aborts based on feedback from each transaction manager.

This setup ensures that transactions are managed smoothly across distributed sites.

2. (b) Briefly describe tightly coupled system and loosely coupled


system with appropriate diagrams.
Answer:

● 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.

3. (a) How can a query be optimized? Briefly describe "Selections on


Cartesian products can be re-written as Theta joins" with examples.
Answer: Query optimization involves improving a query’s efficiency.
Instead of performing a Cartesian product (every row from one table matched with every row
from another), we can use Theta joins to only join rows meeting a specific condition, saving
time and resources.

For example:

● Cartesian Product: All rows of A and B are combined.


● Theta Join: Only rows where A.id = B.id are combined, reducing unnecessary data.

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:

● Instructor (ID, name, dept_name, salary)


● Teaches (ID, course_id, sec_id, semester, year)
● Course (course_id, title, dept_name, credits)

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.

3. (c) How does indexing help to optimize search techniques? Write


down different types of indexing techniques.
Answer: Indexing speeds up data retrieval by creating a sorted structure for quick access
to rows based on key columns.

Types of indexing techniques:

1. Primary Index: Based on a unique attribute, usually the primary key.


2. Secondary Index: Additional index on non-primary key columns.
3. Clustered Index: Sorts data physically according to key values.
4. Non-Clustered Index: Creates a separate structure pointing to data rows.

4. (a) Define Online Analytical Processing (OLAP).


Answer: OLAP is a technology that allows users to analyze large datasets for insights. It
supports complex queries on historical data, often used for reporting and business
intelligence.

4. (b) Differentiate between cube and rollup operations using the 'sales'
relation schema (item-name, color, size, number).
Answer:

● Cube: Computes aggregates for all possible combinations of specified dimensions.


For example, sales data summarized by item-name, color, and size.
● Rollup: Aggregates data at increasing levels of hierarchy. For example, it may first
aggregate sales by color and then by item-name only, summarizing as it goes up.

4. (c) Explain data warehousing with its design issues.


Answer: A data warehouse is a central repository of integrated data from multiple sources,
designed for analysis and reporting.

Design Issues:

1. Data Integration: Combining data from various sources consistently.


2. Data Quality: Ensuring data is accurate and clean.
3. Storage Optimization: Balancing storage costs and retrieval efficiency.
4. Scalability: Ensuring the warehouse can grow with data needs.

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:

● Group 1 (Shorter & Lighter): S1(2,1), S2(3,2), S3(5,2)


● Group 2 (Taller & Heavier): S4(6,3), S5(3,4), S6(5,7)
This clustering separates individuals by physical traits like height and weight.

6. (a) What are mandatory access control and discretionary access


control in DBMS?
Answer:

● Mandatory Access Control (MAC): Access is controlled by the system based on


security labels. Users have no control over permissions; it’s managed according to
strict policies. Typically used in government or highly secure environments.
● Discretionary Access Control (DAC): Access is controlled by the data owner, who
decides who can access or modify data. More flexible and commonly used in
business environments, but less secure than MAC.

6. (b) Write the SQL to grant privileges based on the following


requirements for the schema created by Hosen Miah.
Schema:

● Sailors (sid: integer, sname: string, rating: integer, age: real)


● Boats (bid: integer, bname: string, color: string)
● Reserves (sname: string, bid: integer, day: date)

Grant INSERT and SELECT privileges to Kuber on Sailors table.


sql
GRANT INSERT, SELECT ON Sailors TO Kuber;

1.

Grant SELECT and INSERT privileges to Shitol Babu on Boats table.


sql
GRANT SELECT, INSERT ON Boats TO Shitol_babu;

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.

Revoke all privileges provided to Kuber.


sql
REVOKE ALL PRIVILEGES ON Sailors FROM Kuber;

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.

Example of SQL Injection: Suppose a login query is:

sql
SELECT * FROM Users WHERE username = 'user' AND password = 'pass';

If a hacker enters user' OR '1'='1 as the username, the query becomes:

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.

7. (a) What are the objectives of concurrency control? Describe locking-


based concurrency control protocol.
Answer: Objectives of Concurrency Control:

1. Data Consistency: Ensure accurate results despite simultaneous access.


2. Isolation: Prevent transactions from interfering with each other.
3. Order of Execution: Avoid conflicts and keep transactions in a logical order.

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:

● Shared Lock (S): Allows multiple transactions to read.


● Exclusive Lock (X): Only one transaction can write.

Locks ensure that no conflicting operations occur simultaneously, maintaining consistency


and isolation.

7. (b) Describe the Two-Phase Locking (2PL) protocol.


Answer: Two-Phase Locking (2PL) is a protocol to ensure transaction serializability. It has
two phases:

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.

You might also like