2080.1

CSC265 · TU past paper

Database Management System 2080.1 question paper

The complete TU 2080.1 exam paper for Database Management System (CSC265), all 12 questions with solved model answers written to the mark scheme.

Tap a question to open its answer.

  1. 110 marksComplex Retrieval QueriesAnswer

    Consider a banking database with three tables and primary key underlined as given below: Customer(CustomerID, CustomerName, Address, Phone, Email) Borrows(CustomerID, LoanNumber) Loan(LoanNumber, LoanType, Amount) Write both relational algebra and SQL queries: a. To display name of all customers who live in “Lalitpur” in ascending order of name. b. To count total number of customers having loan at the bank. c. To find name of those customers who have loan amount greater than or equal to 500000. d. To find average loan amount of each account type.[10]

    • Customer(<uCustomerID</u, CustomerName, Address, Phone, Email) - Borrows(<uCustomerID</u, <uLoanNumber</u) - Loan(<uLoanNumber</u, LoanType, Amount) --- $$\tau{CustomerName}(\pi{CustomerName}(\sigma{Address='Lalitpur'}(Customer)))$$ Wh...
  2. 210 marksInformal Design Guidelines for Relational Answer

    What are informal design guidelines for relational schemas? why do we need functional dependencies? Explain 2NF, 3NF with suitable example.[10]

    --- Informal guidelines are used as measures to determine the quality of relation schema design. The four main guidelines are: --- Design a relation schema so that it is easy to explain its meaning. Do not combine attributes from multipl...

  3. 310 marksTwo-Phase Locking TechniqueAnswer

    Explain deadlock with example. What are different deadlock prevention protocols? Explain deadlock detection and starvation.[10]

    Deadlock: Explanation, Prevention, Detection, and Starvation

    1. What is Deadlock?

    Deadlock is a condition in a database system (or operating system) where no process proceeds for execution and each process waits for resources that have been acquired by other processes. In other words, a set of transactions are permanently blocked, each waiting for another to release a lock, and none can proceed.

    "Deadlock is a condition where no process proceeds for execution and each waits for resources that have been acquired by the other processes."


    Example of Deadlock

    Consider two transactions T1 and T2, and two data items X and Y:

    StepTransaction T1Transaction T2
    1Lock(X) -- success
    2Lock(Y) -- success
    3Lock(Y) -- waits (Y held by T2)
    4Lock(X) -- waits (X held by T1)
    • T1 holds X and waits for Y.
    • T2 holds Y and waits for X.
    • Neither can proceed. This is a deadlock.

    2. Deadlock Prevention Protocols

    Deadlock prevention protocols ensure that the system never enters a deadlock state. Several schemes have been proposed, many using the concept of transaction timestamps.

    "A transaction timestamp is a unique identifier assigned to each transaction."

    a) Wait-Die Scheme (Non-Preemptive)

    • If transaction Ti requests a resource held by Tj:
      • If Ti is older (smaller timestamp) than Tj, Ti is allowed to wait.
      • If Ti is younger (larger timestamp) than Tj, Ti dies (is rolled back and restarted).
    • Older transactions wait; younger transactions are aborted.

    Rule: Wait or Die

    If TS(Ti) < TS(Tj)  --> Ti waits
    If TS(Ti) > TS(Tj)  --> Ti dies (aborts)
    

    b) Wound-Wait Scheme (Preemptive)

    • If transaction Ti requests a resource held by Tj:
      • If Ti is older than Tj, Ti wounds (preempts/aborts) Tj.
      • If Ti is younger than Tj, Ti waits.
    • Older transactions preempt younger ones; younger transactions wait.

    Rule: Wound or Wait

    If TS(Ti) < TS(Tj)  --> Ti wounds Tj (Tj aborts)
    If TS(Ti) > TS(Tj)  --> Ti waits
    

    c) Timeout-Based Scheme

    "If a transaction waits for a period longer than a system-defined timeout period, the system assumes that the transaction may be deadlocked and aborts it -- regardless of whether a deadlock actually exists."

    • Simple and practical due to low overhead.
    • A transaction waiting beyond the timeout limit is automatically aborted and restarted.
    • Limitation: May abort transactions that are not actually deadlocked (false positives).

    Comparison Table

    SchemeApproachWho Aborts
    Wait-DieNon-preemptiveYounger transaction
    Wound-WaitPreemptiveYounger transaction (preempted by older)
    TimeoutTime-basedTransaction exceeding timeout

    3. Deadlock Detection

    "An alternative approach to deal with deadlock is deadlock detection, where the system checks if a state of deadlock actually exists."

    When deadlock prevention is not used, the system must detect and recover from deadlocks.

    How Deadlock Detection Works

    The system maintains a Wait-For Graph (WFG):

    • Nodes represent transactions.
    • A directed edge Ti --> Tj means Ti is waiting for a resource held by Tj.
    • A deadlock exists if and only if there is a cycle in the Wait-For Graph.

    Example:

    T1 --> T2 --> T3 --> T1   (Cycle detected = Deadlock!)
    

    Detection Algorithm Steps

    1. Build the Wait-For Graph from current lock and wait information.
    2. Periodically invoke a cycle-detection algorithm.
    3. If a cycle is found, select a victim transaction (usually the youngest or least-cost transaction).
    4. Abort (rollback) the victim transaction to break the cycle.
    5. Release all locks held by the victim and restart it later.

    When to Invoke Detection

    • After every lock request (high overhead, fast detection).
    • Periodically at fixed time intervals (lower overhead, delayed detection).

    "This solution is attractive if different transactions will rarely access the same items at the same time."


    4. Starvation

    "Starvation is a condition where process with higher priorities continuously uses the resources preventing low priority process to acquire the resources."

    Starvation occurs when a transaction is indefinitely delayed because other transactions (usually of higher priority) continuously acquire the resources it needs. Unlike deadlock, in starvation some processes do proceed -- just not the starved one.

    Difference Between Deadlock and Starvation

    AspectDeadlockStarvation
    DefinitionNo process proceeds; all wait for each otherSome processes proceed; one is indefinitely delayed
    CauseCircular wait among processesPriority-based resource allocation
    Processes involvedAll involved processes are blockedOnly the low-priority process is blocked
    ResolutionAbort victim, break cycleAging (gradually increase priority)

    How Starvation Occurs in Deadlock Recovery

    When the system repeatedly selects the same transaction as victim during deadlock recovery, that transaction is continuously rolled back and never completes -- this is starvation.

    Prevention of Starvation

    • Aging: Gradually increase the priority of a waiting transaction over time so it eventually
  4. 45 marksCharacteristics of the Database ApproachAnswer

    What are the characteristics of database approach? Explain. [5]

    The database approach has several important characteristics that distinguish it from traditional file-based systems. Among these, three most important characteristics form the basis of the three-schema architecture, which was proposed to...

  5. 55 marksThree-Schema Architecture and Data IndepenAnswer

    Define data independence. Explain three-schema architecture. [5]

    Data Independence and Three-Schema Architecture


    Data Independence

    Data independence is the capacity to change the schema at one level of a database system without having to change the schema at the next higher level.

    There are two types of data independence:

    1. Logical Data Independence

    It is the capacity to change the conceptual schema without having to change the external schemas or application programs. For example, we may add new entity types, change constraints, or reduce the database. Only the view definition and mappings need to be updated; the external/user views remain unaffected.

    2. Physical Data Independence

    It is the capacity to change the internal schema without having to change the conceptual schema (and hence the external schemas also need not change). Changes to the internal schema may be needed because physical files were reorganized or storage structures were modified. As long as the same data remains in the database, the conceptual schema should not need to change.


    Three-Schema Architecture

    The goal of the three-schema architecture is to separate user applications from the physical database, thereby achieving data independence and data abstraction.

    The three schemas are only descriptions of data; the actual data is stored at the physical level only. Requests and results are transformed between levels through a process called mappings.

    External Users
          |
      [External Level]  -- External Views (View 1, View 2, ...)
          |
      External/Conceptual Mapping
          |
      [Conceptual Level] -- Conceptual Schema
          |
      Conceptual/Internal Mapping
          |
      [Internal Level]  -- Internal Schema
          |
      Stored Database
    

    Level 1: External Level (View Level)

    • The highest level of abstraction.
    • Describes the part of the database that a particular user group is interested in.
    • Each user group has its own external view (also called a subschema).
    • Hides the rest of the database from that user group.
    • Defined using View Definition Language (VDL).

    Level 2: Conceptual Level

    • Describes what data is stored in the database and the relationships among the data for the entire organization.
    • Hides the details of physical storage structures.
    • Represents the logical structure of the whole database (entities, attributes, constraints, relationships).
    • Defined using Data Definition Language (DDL).

    Level 3: Internal Level (Physical Level)

    • The lowest level of abstraction.
    • Describes how data is physically stored on storage media (file organization, indexing, access paths, record formats, etc.).
    • Defined using Storage Definition Language (SDL).

    Summary Table

    LevelAlso CalledDescribesLanguage
    ExternalView LevelUser-specific viewsVDL
    ConceptualLogical LevelWhole database structureDDL
    InternalPhysical LevelPhysical storage detailsSDL

    Note: Most DBMSs do not completely and explicitly separate the three levels, but they support the three-schema architecture to some extent.

  6. 65 marksSpecialization and GeneralizationAnswer

    What is specialization? What are different constraints on specialization? [5]

    Specialization is a top-down approach in database design where one higher-level entity (superclass) is broken down into two or more lower-level entities (subclasses). It maximizes the differences between members of an entity by identifyi...

  7. 75 marksRelational Model ConceptsAnswer

    What is relational database? Explain different characteristic of a relation. Defain domain constraint. [5]

    --- A relational database is a database that organizes and stores data in the form of tables (relations). Each table consists of rows (tuples) and columns (attributes). It is based on the relational data model proposed by E.F. Codd. Well...

  8. 85 marksNumericalthe Tuple Relational CalculusAnswer

    What is tuple realtion calculus ? Given the following schema, write tuple relational calculus for selecting name and address of employee who are working in a company having Cid=E01. Employee(Eid, Ename, Address, Cid) Company(Cid, CName) [5]

    Schema: - Employee(Eid, Ename, Address, Cid) - Company(Cid, CName) Requirement: Retrieve Ename and Address of employees working in a company with Cid = E01. No numeric matrices or missing data; this is a conceptual/query question. --- Tu...

  9. 95 marksCharacterizing Schedules Based on RecoveraAnswer

    Explain schedule based on recoverability and serializability. [5]

    A serializable schedule is a concurrent schedule whose final result is exactly the same as the result produced by some serial schedule (where transactions execute one after another without interleaving). Serializability is the standard c...

  10. 105 marksTimestamp OrderingAnswer

    How timestamp ordering protocol is used for ensuring concurrency control? [5]

    A timestamp is a unique identifier assigned to each transaction by the DBMS, typically based on the system clock or a logical counter at the time the transaction starts. The timestamp ordering protocol uses these timestamps to determine ...

  11. 115 marksRecovery Technique Based on Immediate UpdaAnswer

    Why database recovery is essential? Explain recovery technique based on immediate update. [5]

    Database recovery is essential due to the following reasons: - System Crashes and Failures: Hardware or software failures can occur in the middle of a transaction, leaving the database in an inconsistent state. - Transaction Errors: Inco...

  12. 125 marksIntroduction to Transaction ProcessingAnswer

    Write short notes on: a. Transaction processing b. Weak entity [5]

    Definition: A transaction is an executing program or process that includes one or more database access operations such as reading or updating of database records. Key Concepts: - Applications that manage transactions are generally called...