Skip to main content

Chapter 2

Database Management System

TU BCA past exam questions

Past questions and answers

67 questions set from this chapter, 1 of them more than once; 1 is most repeated (set, or a close variant set, in 3 or more exams). Most repeated first.

  • Most repeated · 3 of 8 exams
  • Asked 3 times
  • 2020 · 5 marks
  • 2022 · 5 marks
  • 2026 · 5 marks

Why indexing is essential in database? Differentiate dense index from sparse index with suitable example.

Answer

Why indexing is essential

An index is a data structure (such as a B+ tree or hash table) that stores search-key values together with pointers to the records having that key. Without an index, the DBMS must scan the whole file sequentially to find a record, which is slow for large tables. An index:

  • speeds up the retrieval of records by search key (equality and range queries), reducing disk block accesses;
  • speeds up sorting, joins and ORDER BY/GROUP BY operations;
  • helps to enforce uniqueness of keys.

The cost is extra storage and slower inserts, updates and deletes, since the index must be maintained.

Dense index versus sparse index

Dense indexSparse index
Has an index entry for every search-key value (every record) in the data file.Has index entries for only some search-key values (usually one per data block).
Searching is faster, since the exact key is found directly in the index.The largest entry with key ≤\le the search key is found, then the data block is scanned sequentially.
Needs more space and more maintenance.Needs less space and less maintenance.
Can be used whether or not the file is sorted on the key (secondary index must be dense).The data file must be sorted on the search key.

Example: a file sorted on roll number, with records 101, 102, 103, 104, 105, 106, stored 3 per block.

  • Dense index: entries 101, 102, 103, 104, 105, 106, each pointing to its own record.
  • Sparse index: entries 101 (block 1) and 104 (block 2). To find 105, the entry 104 is located (the largest entry ≤\le 105), block 2 is read and scanned to find 105.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2020 · 5 marks

What is DBMS? Describe the merits of using DBMS.

Answer

A Database Management System (DBMS) is software that allows users to define, create, store, maintain, retrieve and control access to a database. It acts as an interface between the database and users or application programs. Examples: MySQL, Oracle, SQL Server, PostgreSQL.

Merits (advantages) of using a DBMS

  1. Reduced data redundancy: data is stored in one place, avoiding duplication of data across files.
  2. Data consistency: since redundancy is controlled, all users see the same, up-to-date data.
  3. Data sharing: many users and applications can share the same data at the same time.
  4. Data integrity: integrity constraints (primary key, foreign key, check, not null) keep the data correct and valid.
  5. Data security: authentication, authorization and privileges control who can see or change what.
  6. Data independence: physical and logical structure can be changed without changing the application programs.
  7. Backup and recovery: the DBMS restores the database after a failure or a crash.
  8. Concurrency control: the DBMS manages simultaneous access so that transactions do not interfere.
  9. Easy and efficient data access: query languages like SQL give quick, flexible retrieval.
  10. Standards and reduced application development time.

Drawbacks are the cost of software and hardware, complexity, and need for trained staff.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2020 · 5 marks

What is Data Model? What is the difference between hierarchical and network data model? what are its types?

Answer

A data model is a collection of concepts and tools for describing the structure of a database: the data, the relationships between data, the semantics and the constraints. It gives the means to achieve data abstraction.

Types of data models

  1. Hierarchical model: data is organised as a tree of records.
  2. Network model: data is organised as a graph of records.
  3. Relational model: data is stored in tables (relations) of rows and columns.
  4. Entity-Relationship (E-R) model: a high-level conceptual model using entities, attributes and relationships.
  5. Object-oriented / object-relational model: data is stored as objects with attributes and methods.
  6. Semi-structured models such as XML/JSON, and document or key-value models for NoSQL.

Hierarchical versus network data model

Hierarchical modelNetwork model
Records are arranged in a tree structure with one root.Records are arranged as a graph.
Each child record has exactly one parent (one-to-many relationship).A record can have more than one parent (many-to-many supported).
Many-to-many relationships need redundant data.Many-to-many relationships are represented directly using set types/links.
Simple structure, but inflexible and has redundancy.More flexible but the structure is more complex.
Navigation always begins at the root and goes down.Navigation can start at any record and follow links.
Example: IBM IMS.Example: IDMS, based on CODASYL.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2020 · 5 marks

Discuss about materialized and pipelined evaluation of query expression in query optimization.

Answer

A query is represented as an expression tree of relational algebra operators, and the optimizer must decide how to evaluate the tree. There are two approaches.

Materialized evaluation

Operations of the expression are evaluated one at a time, usually from the lowest level of the tree upward. The result of each operation is stored (materialized) in a temporary relation on disk, and is used as the input to the next operation.

  • Example: for πname(σdept="CS"(Student⋈Enroll))\pi_{name}(\sigma_{dept="CS"}(Student \bowtie Enroll)), first the join is computed and written to a temporary relation T1T_1; then σ\sigma is applied to T1T_1 giving T2T_2; finally π\pi is applied.
  • Advantage: simple and always applicable.
  • Disadvantage: the cost includes writing and reading the temporary relations, which takes extra disk I/O and space.

Pipelined evaluation

Several operations are evaluated simultaneously in a pipeline: the output tuples of one operation are passed directly as input to the next operation without being stored in a temporary relation.

  • It can be demand-driven (lazy: the parent requests the next tuple from the child) or producer-driven (eager: operators produce tuples into buffers until full).
  • Example: the selection and projection above can be applied to each tuple coming out of the join, with no temporary relation.
  • Advantage: no temporary file I/O, lower cost, quicker first results.
  • Disadvantage: not applicable to blocking operators such as sorting and some joins that need the whole input, and pipelined operators cannot always use the best algorithm (e.g. a merge join needs sorted inputs).

Summary: materialization stores intermediate results; pipelining avoids storage, so it is usually cheaper when possible.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2020 · 5 marks

Explain with examples, how lost update and dirty read problems can occur in sentence of transactions?

Answer

When transactions run concurrently without proper control, the interleaving of their operations can give incorrect results. Two such problems are the lost update and the dirty read.

1. Lost update problem

This happens when two transactions read the same data item and both update it based on the old value, so the update of one is overwritten by the other.

Example: let A=100A = 100 initially. T1T_1 withdraws 10 and T2T_2 deposits 50.

TimeT1T_1T2T_2A
1read(A) -> 100100
2read(A) -> 100100
3A = A - 10 = 90
4A = A + 50 = 150
5write(A)90
6write(A)150

The correct final value is 100−10+50=140100 - 10 + 50 = 140, but the database has 150: the update of T1T_1 is lost.

2. Dirty read (temporary update) problem

This happens when a transaction reads a value written by another transaction that has not yet committed. If the writer later aborts and rolls back, the reader has used a value that never officially existed.

Example:

TimeT1T_1T2T_2
1read(A) -> 100
2A = A - 20; write(A) -> 80
3read(A) -> 80 (dirty)
4A = A + 10; write(A) -> 90; commit
5abort (rollback A to 100)

T2T_2 read the uncommitted value 80 and wrote 90 based on it. After T1T_1 rolls back, the correct value should be 110, but the database holds an inconsistent value. This may also cause cascading rollbacks.

These problems are prevented by concurrency control (locking, timestamp ordering) and appropriate isolation levels.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2020 · 5 marks

How time stamp ordering protocol is used to ensure concurrency control?

Answer

Timestamp ordering protocol is a concurrency-control method that decides the serialisability order of transactions in advance using timestamps, without locks.

Timestamps

  • Each transaction TiT_i gets a unique timestamp TS(Ti)TS(T_i) when it enters the system (system clock or logical counter). An older transaction has a smaller timestamp.
  • Each data item QQ keeps two values:
    • W-TS(Q)W\text{-}TS(Q): the largest timestamp of any transaction that successfully wrote QQ.
    • R-TS(Q)R\text{-}TS(Q): the largest timestamp of any transaction that successfully read QQ.

The protocol ensures that conflicting operations are executed in timestamp order, so the schedule is equivalent to the serial schedule in timestamp order.

Rules

Transaction TiT_i issues read(QQ):

  • If TS(Ti)<W-TS(Q)TS(T_i) < W\text{-}TS(Q): TiT_i would read a value that has already been overwritten, so the read is rejected and TiT_i is rolled back (restarted with a new timestamp).
  • Otherwise the read is executed and R-TS(Q)=max⁡(R-TS(Q),TS(Ti))R\text{-}TS(Q) = \max(R\text{-}TS(Q), TS(T_i)).

Transaction TiT_i issues write(QQ):

  • If TS(Ti)<R-TS(Q)TS(T_i) < R\text{-}TS(Q): a younger transaction has already read the value that TiT_i is producing now, so the write is rejected and TiT_i is rolled back.
  • If TS(Ti)<W-TS(Q)TS(T_i) < W\text{-}TS(Q): TiT_i is writing an obsolete value, so the write is rejected and TiT_i is rolled back. (Thomas' write rule simply ignores this obsolete write.)
  • Otherwise the write is executed and W-TS(Q)=TS(Ti)W\text{-}TS(Q) = TS(T_i).

Example: let TS(T1)=5TS(T_1) = 5, TS(T2)=10TS(T_2) = 10. If T2T_2 writes QQ (W-TS=10W\text{-}TS = 10) and later T1T_1 tries to read QQ, then 5<105 < 10, so T1T_1 is rolled back.

Properties: it guarantees conflict serialisability and is free from deadlock, since transactions never wait. It may cause starvation of a transaction that is repeatedly restarted, and it can produce cascading rollbacks or non-recoverable schedules unless extra checks (such as waiting for commit) are made.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2020 · 5 marks

What is the advantage and Disadvantage of using stored procedure? How can you create and execute stored procedure?

Answer

A stored procedure is a named collection of precompiled SQL statements (with optional control-flow logic) that is stored in the database and can be executed by calling its name with parameters.

Advantages

  1. Better performance: it is parsed and compiled once, and the execution plan is cached.
  2. Reduced network traffic: only the call is sent to the server instead of many SQL statements.
  3. Reusability and modularity: the business logic is written once and used by many applications.
  4. Security: users can be given permission to execute the procedure without direct access to the underlying tables; it also helps against SQL injection when parameterised.
  5. Easy maintenance: a change in the logic is made in one place only.
  6. Consistency and transaction control of operations.

Disadvantages

  1. Hard to debug and test compared with application code.
  2. Business logic in the database makes it vendor specific (the procedural syntax differs among DBMSs), so portability is reduced.
  3. Heavy use increases the load on the database server.
  4. Version control and deployment are more difficult.

Creating and executing a stored procedure (MySQL)

DELIMITER //
CREATE PROCEDURE GetStudentsByDept (IN dept_name VARCHAR(30))
BEGIN
    SELECT roll_no, name
    FROM Student
    WHERE department = dept_name;
END //
DELIMITER ;

Execution:

CALL GetStudentsByDept('Computer');

In SQL Server the equivalent is:

CREATE PROCEDURE GetStudentsByDept @dept VARCHAR(30)
AS
BEGIN
    SELECT roll_no, name FROM Student WHERE department = @dept;
END;

EXEC GetStudentsByDept 'Computer';

It can be removed using DROP PROCEDURE GetStudentsByDept;.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2020 · 10 marks

Design an ER diagram for Hospital System. Use your assumption for the selection attributes, entities and relationships. Show the use of total and partial participation along with the appropriate cardinalities.

Answer

Assumptions

The hospital has patients, doctors, departments, wards/rooms, nurses and treatments (appointments).

Entities and attributes (primary keys underlined by *)

  • PATIENT(PatientID*, Name, Address, Phone, DOB, Gender)
  • DOCTOR(DoctorID*, Name, Specialization, Phone, Salary)
  • DEPARTMENT(DeptID*, DeptName, Location)
  • WARD(WardNo*, WardType, Capacity)
  • NURSE(NurseID*, Name, Shift)
  • APPOINTMENT (relationship attributes: Date, Time, Diagnosis, Fee)

Relationships, cardinalities and participation

RelationshipEntitiesCardinalityParticipation
WORKS_INDOCTOR - DEPARTMENTmany-to-one (N:1)DOCTOR total (every doctor works in a department); DEPARTMENT total
TREATS (Appointment)DOCTOR - PATIENTmany-to-many (M:N), attributes Date, Diagnosis, FeeDOCTOR partial (a doctor may have no patient yet); PATIENT total (a patient is registered because of a doctor visit)
ADMITTED_TOPATIENT - WARDmany-to-one (N:1), attribute AdmitDatePATIENT partial (not all patients are admitted); WARD partial (a ward may be empty)
ASSIGNED_TONURSE - WARDmany-to-one (N:1)NURSE total; WARD partial
HEADSDOCTOR - DEPARTMENTone-to-one (1:1)DOCTOR partial (only some are heads); DEPARTMENT total (each has a head)

ER diagram (text form: rectangle = entity, diamond = relationship, == = total participation, -- = partial participation)

 (Name)(Phone)                      (DeptName)(Location)
      \   |                             \   |
      [ DOCTOR ] ==N=== <WORKS_IN> ==1== [ DEPARTMENT ]
        |   \                                   ||
        M    \--1-- <HEADS> -- partial ---------+ (total)
        |
     <TREATS>  (Date, Diagnosis, Fee)
        |
        N  (total)
        |
     [ PATIENT ] --N-- <ADMITTED_TO>(AdmitDate) --1-- [ WARD ] --1-- <ASSIGNED_TO> --N== [ NURSE ]
      PatientID, Name,   (partial)         (partial)   WardNo,                          (total)
      Address, Phone, DOB                              WardType

Notes

  • Total participation (double line) means every entity instance must take part in the relationship; for example every DOCTOR must work in some DEPARTMENT.
  • Partial participation (single line) means participation is optional, for example a PATIENT need not be admitted to a WARD.
  • Converted to relations, the N:1 relationships become foreign keys on the N side (Doctor.DeptID, Patient.WardNo, Nurse.WardNo) and the M:N relationship TREATS becomes a table Treats(DoctorID, PatientID, Date, Diagnosis, Fee).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2020 · 10 marks

Discuss the importance of normalization in DBMS. Describe 1NF, 2NF and 3NF with examples.

Answer

Importance of normalization

Normalization is the process of organising the attributes and tables of a relational database to minimise redundancy and avoid anomalies, by decomposing relations using functional dependencies. Its importance:

  1. Reduces data redundancy and saves storage.
  2. Removes insertion, update and deletion anomalies.
  3. Keeps the data consistent and maintains integrity.
  4. Gives a clear, logical design, with decomposition that is lossless and (ideally) dependency preserving.
  5. Makes queries and maintenance of the database easier.

First Normal Form (1NF)

A relation is in 1NF if every attribute holds only atomic (indivisible) values: no multivalued attributes or repeating groups.

Not in 1NF:

StudentIDNamePhone
1Ram9841, 9851

1NF:

StudentIDNamePhone
1Ram9841
1Ram9851

Second Normal Form (2NF)

A relation is in 2NF if it is in 1NF and no non-prime attribute is partially dependent on a part of a candidate key (every non-key attribute is fully functionally dependent on the whole key).

Example: Enroll(StudentID, CourseID, StudentName, Grade) with key (StudentID,CourseID)(StudentID, CourseID). Here StudentID→StudentNameStudentID \to StudentName is a partial dependency, so it is not in 2NF. Decompose:

  • Student(StudentID, StudentName)
  • Enroll(StudentID, CourseID, Grade)

Third Normal Form (3NF)

A relation is in 3NF if it is in 2NF and no non-prime attribute is transitively dependent on the key; i.e. for every non-trivial X→AX \to A, either XX is a superkey or AA is a prime attribute.

Example: Student(StudentID, Name, DeptID, DeptName) with StudentID→DeptIDStudentID \to DeptID and DeptID→DeptNameDeptID \to DeptName. DeptNameDeptName is transitively dependent on StudentIDStudentID, so it is not in 3NF. Decompose:

  • Student(StudentID, Name, DeptID)
  • Department(DeptID, DeptName)

Each step produces relations that are free of more kinds of anomalies. For instance, after the 3NF split, a department name is stored once, and changing it needs only one update.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2020 · 10 marks

Consider a database system with following schemes:
Restaurant(Rname, Rlocation, Rfund)
Cook(Cname, Cspeciality)
Worksat(Cname, Rname, Workinghrs, Shift)
Food(Fname, Cname, Catagory)
Now write SQL statements and relational algebra statements for following Queries:
a) Select the name and location of all restaurants.
b) Find the working hours of cook named "Sita".
c) Select name of the foods cooked by "Ramesh".
d) Use join to select name of restaurants where food of category "breakfast" is available.
e) Find the name of cooks who work as "KFC"

Answer

Schemas:

  • Restaurant(Rname, Rlocation, Rfund)
  • Cook(Cname, Cspeciality)
  • Worksat(Cname, Rname, Workinghrs, Shift)
  • Food(Fname, Cname, Catagory)

(a) Name and location of all restaurants

SQL:

SELECT Rname, Rlocation FROM Restaurant;

Relational algebra:

πRname, Rlocation(Restaurant)\pi_{Rname,\,Rlocation}(Restaurant)

(b) Working hours of cook named "Sita"

SELECT Workinghrs FROM Worksat WHERE Cname = 'Sita';

πWorkinghrs(σCname=′Sita′(Worksat))\pi_{Workinghrs}(\sigma_{Cname='Sita'}(Worksat))

(c) Names of foods cooked by "Ramesh"

SELECT Fname FROM Food WHERE Cname = 'Ramesh';

πFname(σCname=′Ramesh′(Food))\pi_{Fname}(\sigma_{Cname='Ramesh'}(Food))

(d) Names of restaurants where food of category "breakfast" is available (using join)

A cook who works at a restaurant and cooks breakfast food makes that food available there.

SELECT DISTINCT w.Rname
FROM Worksat w
JOIN Food f ON w.Cname = f.Cname
WHERE f.Catagory = 'breakfast';

πRname(Worksat⋈Worksat.Cname=Food.CnameσCatagory=′breakfast′(Food))\pi_{Rname}\big(Worksat \bowtie_{Worksat.Cname = Food.Cname} \sigma_{Catagory='breakfast'}(Food)\big)

(e) Names of cooks who work at "KFC"

SELECT Cname FROM Worksat WHERE Rname = 'KFC';

πCname(σRname=′KFC′(Worksat))\pi_{Cname}(\sigma_{Rname='KFC'}(Worksat))

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 5 marks

What is database? Discuss the importance of DBMS.

Answer

A database is an organised collection of related data stored so that it can be easily accessed, managed and updated. For example, a college database holds data about students, teachers, courses and results. A DBMS (Database Management System) is the software (MySQL, Oracle, PostgreSQL, SQL Server) used to define, create, store, retrieve and control access to the database.

Importance of DBMS

  1. Reduced data redundancy and inconsistency: data is stored centrally, so the same fact is not repeated in many files.
  2. Data sharing: many users and applications can use the same data at the same time.
  3. Data independence: programs are insulated from changes in the physical storage or logical structure of data.
  4. Data integrity: integrity constraints (primary key, foreign key, check, not null) keep data correct and valid.
  5. Security: access is controlled through user accounts, privileges and roles.
  6. Backup and recovery: the DBMS restores the database to a consistent state after a crash or failure.
  7. Concurrency control: transactions of many users are executed without interfering with each other.
  8. Efficient access: indexing, query optimisation and a query language (SQL) give fast retrieval of data.
  9. Standards and reduced development time: common standards and ready-made services make application development quicker.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 5 marks

Define union compatibility. Given following relations, show the resulting relation of Director ∩ Actor and Actor ∪ Director?
Director
FnameLname
DeepakGiri
BhuwanKC
DipendraKhanel
Actor
First nameLast name
DeepakGiri
RajeshHamal
DipendraKhanel

Answer

Union compatibility. Two relations R(A1,…,An)R(A_1,\dots,A_n) and S(B1,…,Bm)S(B_1,\dots,B_m) are union compatible (type compatible) if

  1. they have the same number of attributes, i.e. n=mn = m, and
  2. the corresponding attributes have the same domain (data type), i.e. dom(Ai)=dom(Bi)\text{dom}(A_i)=\text{dom}(B_i) for every ii.

Attribute names may differ. The operations union (∪\cup), intersection (∩\cap) and difference (−-) can be applied only to union-compatible relations. The result takes the attribute names of the first relation.

Here Director(Fname, Lname) and Actor(First name, Last name) both have two string attributes, so they are union compatible.

Director ∩\cap Actor (tuples present in both):

FnameLname
DeepakGiri
DipendraKhanel

Actor ∪\cup Director (all distinct tuples, duplicates removed; the result uses the attribute names of Actor):

First nameLast name
DeepakGiri
RajeshHamal
DipendraKhanel
BhuwanKC

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 5 marks

How Order By and Group BY Having Clause in SQL are different? Illustrate with suitable examples.

Answer

Both clauses organise the output of a query, but they do different jobs.

BasisORDER BYGROUP BY ... HAVING
PurposeSorts the rows of the result in ascending (ASC) or descending (DESC) orderGroups rows having the same value in the given column(s) so that aggregate functions work per group
Number of rowsDoes not change the number of rowsProduces one row per group
AggregatesNot requiredNormally used with COUNT, SUM, AVG, MAX, MIN
ConditionNo condition of its ownHAVING filters groups (WHERE filters rows before grouping)
PositionLast clause of the queryBefore ORDER BY, after WHERE

Consider Employee(eid, name, dept, salary).

ORDER BY example: list employees by salary, highest first.

SELECT name, dept, salary
FROM Employee
ORDER BY salary DESC;

GROUP BY ... HAVING example: show departments whose average salary is more than 30000.

SELECT dept, COUNT(*) AS total, AVG(salary) AS avg_sal
FROM Employee
GROUP BY dept
HAVING AVG(salary) > 30000;

Both together: the same result sorted by average salary.

SELECT dept, AVG(salary) AS avg_sal
FROM Employee
GROUP BY dept
HAVING AVG(salary) > 30000
ORDER BY avg_sal DESC;

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 5 marks

Why normalization is needed? When any relation is said to be in 1NF and 2NF?

Answer

Normalization is the process of organising the attributes and tables of a relational database to reduce redundancy and avoid insertion, deletion and update anomalies.

Why it is needed

  • It removes redundant data, which saves storage.
  • It avoids update anomalies (the same fact must be changed in many rows), insertion anomalies (a fact cannot be stored without another) and deletion anomalies (deleting one fact loses another).
  • It keeps data consistent and makes the design clearer and easier to maintain.

First Normal Form (1NF). A relation is in 1NF if every attribute holds only atomic (indivisible) values: no multivalued or composite attributes and no repeating groups. Example: Student(Roll, Name, Phones) with Phones = {9801, 9802} is not in 1NF. Giving each phone its own row, Student(Roll, Name, Phone), makes it 1NF.

Second Normal Form (2NF). A relation is in 2NF if it is in 1NF and every non-key attribute is fully functionally dependent on the whole primary key, with no partial dependency on part of a composite key. Example: Enroll(Roll, CourseID, StudentName, Grade) with key (Roll, CourseID). Here Roll→StudentNameRoll \rightarrow StudentName is a partial dependency, so it is not in 2NF. Decompose into Student(Roll, StudentName) and Enroll(Roll, CourseID, Grade).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 5 marks

How cost of query is measured during query processing? Construct query expression tree for the relational algebra query: TLFName LName, Address(ODName="Research" ∧ Department Dnumber=Dno (Employee * Works_on))

Answer

Measuring the cost of a query

The query optimiser chooses the execution plan with the least estimated cost. Cost is mainly measured as the total resource consumption:

  1. Disk (secondary storage) access cost: number of blocks read and written. This usually dominates because disk is far slower than memory.
  2. CPU cost: time for processing tuples, comparisons and computations.
  3. Memory (buffer) usage cost: space for sorting, hashing and temporary results.
  4. Communication cost: data transfer in distributed or client-server systems.
  5. Storage cost of intermediate results.

Total cost = disk access + CPU + memory + communication. The estimate uses catalog statistics such as number of tuples, blocks per relation, distinct values and available indexes, together with the selectivity of conditions. Typically, cost of a plan ≈\approx (number of block transfers ×tT\times t_T) + (number of seeks ×tS\times t_S).

Query expression tree

The query is: project Fname,Lname,AddressFname, Lname, Address over a selection with condition Dname="Research"∧Dnumber=DnoDname=\text{"Research"} \wedge Dnumber=Dno applied to the join of Employee and Works_on (the cross-product of Department and the join of Employee and Works_on in the question). In relational algebra:

πFname, Lname, Address(σDname="Research" ∧ Dnumber=Dno(Department×(Employee⋈Works_on)))\pi_{Fname,\,Lname,\,Address}\big(\sigma_{Dname=\text{"Research"}\ \wedge\ Dnumber=Dno}(\text{Department} \times (\text{Employee} \bowtie \text{Works\_on}))\big)

The tree has relations as leaves and operators as internal nodes, evaluated bottom up:

        π Fname, Lname, Address
                 |
   σ Dname="Research" ∧ Dnumber=Dno
                 |
                 ×
               /   \
       Department    ⋈
                    /  \
              Employee  Works_on

Execution starts at the leaves (Department, Employee, Works_on), joins/products form intermediate relations, then the selection filters tuples and the projection at the root gives the final result. The optimiser may rewrite the tree by pushing the selection Dname="Research"Dname=\text{"Research"} down to Department and replacing selection plus product by a join, which lowers the cost.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 5 marks

How wait-for-graph is constructed? How can you use it to detect deadlock in a schedule of transactions? Support your answer with an example.

Answer

Wait-for-graph construction. A wait-for graph G=(V,E)G=(V,E) is a directed graph used by the lock manager to detect deadlock.

  • Vertices VV: the active transactions.
  • Edge Ti→TjT_i \rightarrow T_j: added when TiT_i requests a lock on a data item that is currently locked by TjT_j in a conflicting mode, so TiT_i must wait for TjT_j.
  • The edge is removed when TjT_j releases the lock and TiT_i obtains it.

Deadlock detection. The system checks the graph periodically. If the graph contains a cycle, a deadlock exists and every transaction in the cycle is deadlocked. If there is no cycle, there is no deadlock. To recover, a victim transaction in the cycle is chosen (usually the cheapest one to roll back) and aborted, which breaks the cycle.

Example. Consider this schedule:

StepT1T_1T2T_2T3T_3
1Lock-X(A)
2Lock-X(B)
3Lock-X(C)
4Lock-X(B) (waits for T2T_2)
5Lock-X(C) (waits for T3T_3)
6Lock-X(A) (waits for T1T_1)

Edges: T1→T2T_1 \rightarrow T_2, T2→T3T_2 \rightarrow T_3, T3→T1T_3 \rightarrow T_1.

The graph has the cycle T1→T2→T3→T1T_1 \rightarrow T_2 \rightarrow T_3 \rightarrow T_1, so the schedule is deadlocked. Aborting T3T_3 (say) releases C, lets T2T_2 proceed, then T1T_1, and the deadlock is resolved.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 5 marks

How read and write operations are performed in a transaction? List the various states where transactions can enter into.

Answer

Read and write operations in a transaction. A transaction accesses the database through two basic operations, working between disk and main-memory buffers:

  • read(X): if the block containing item XX is not in the main-memory buffer, it is first read from disk; then the value of XX is copied into a local variable of the transaction.
  • write(X): the value of the local variable is copied into XX in the buffer (after bringing the block in if needed). The buffer is written to disk later, either immediately or at a time chosen by the buffer manager, and only guaranteed durable after commit.

For example, a transfer of Rs 500 from A to B is: read(A); A := A - 500; write(A); read(B); B := B + 500; write(B).

States of a transaction.

  1. Active: the initial state; the transaction is executing its operations.
  2. Partially committed: after the final statement has executed, but changes may still be only in memory.
  3. Committed: after successful completion; all changes are permanently recorded in the database.
  4. Failed: after normal execution can no longer proceed (hardware, logical error, deadlock).
  5. Aborted: after the transaction is rolled back and the database restored to its state before the transaction began. The system may then restart or kill the transaction.

Transitions: Active → Partially committed → Committed; Active or Partially committed → Failed → Aborted.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 10 marks

Given the schema as below, write relational algebra and SQL queries for following:
Sailors(sid, sname, rating, age)
Boats(bid, bname, colour)
Reserves(sid, bid, reservedate)
a) Find name, rating and age of all the sailors.
b) Find the name and color of boats having color blue.
c) Find name of the boats reserved on date 2021/07/20.
d) Find the names of boats and sailors who have reserved boats having color green.
e) Use Left and Right Outer Join between Sailors and Reserves.

Answer

Schema: Sailors(sid, sname, rating, age), Boats(bid, bname, colour), Reserves(sid, bid, reservedate).

(a) Name, rating and age of all sailors

πsname, rating, age(Sailors)\pi_{sname,\,rating,\,age}(Sailors)

SELECT sname, rating, age FROM Sailors;

(b) Name and colour of blue boats

πbname, colour(σcolour=′blue′(Boats))\pi_{bname,\,colour}(\sigma_{colour='blue'}(Boats))

SELECT bname, colour FROM Boats WHERE colour = 'blue';

(c) Names of boats reserved on 2021/07/20

πbname(Boats⋈(σreservedate=′2021/07/20′(Reserves)))\pi_{bname}\big(Boats \bowtie (\sigma_{reservedate='2021/07/20'}(Reserves))\big)

SELECT DISTINCT b.bname
FROM Boats b JOIN Reserves r ON b.bid = r.bid
WHERE r.reservedate = '2021-07-20';

(d) Names of boats and sailors who have reserved green boats

πbname, sname(σcolour=′green′(Boats)⋈Reserves⋈Sailors)\pi_{bname,\,sname}\big(\sigma_{colour='green'}(Boats) \bowtie Reserves \bowtie Sailors\big)

SELECT b.bname, s.sname
FROM Sailors s
JOIN Reserves r ON s.sid = r.sid
JOIN Boats b ON r.bid = b.bid
WHERE b.colour = 'green';

(e) Left and right outer joins between Sailors and Reserves

Sailors  ⟕Sailors.sid=Reserves.sid  ReservesSailors  ⟖Sailors.sid=Reserves.sid  ReservesSailors \;⟕_{Sailors.sid=Reserves.sid}\; Reserves \qquad Sailors \;⟖_{Sailors.sid=Reserves.sid}\; Reserves

-- Left outer join: all sailors, with reservation data where it exists
SELECT s.sid, s.sname, r.bid, r.reservedate
FROM Sailors s LEFT OUTER JOIN Reserves r ON s.sid = r.sid;

-- Right outer join: all reservations, with sailor data where it exists
SELECT s.sid, s.sname, r.bid, r.reservedate
FROM Sailors s RIGHT OUTER JOIN Reserves r ON s.sid = r.sid;

The left join keeps sailors who never reserved a boat (with NULLs for the Reserves columns); the right join keeps all Reserves rows, with NULLs for the Sailors columns if no matching sailor exists.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 10 marks

a) Design an ER diagram of your choice. The ER diagram should contain at least five entities. Out of those entities, one should be weak entity. Your entities should have appropriate attributes including primary key attributes, if any. There should be presence of one to one relationship, one to many relationship and many to many relationships in your ER diagram.
b) Convert the ER diagram in Q. 19. a. into equivalent relational tables.

Answer

(a) ER diagram: Library Management System

Entities and attributes (primary keys underlined by "PK"):

  • MEMBER(member_id PK, name, address, phone)
  • BOOK(isbn PK, title, price, edition)
  • AUTHOR(author_id PK, name, country)
  • PUBLISHER(pub_id PK, name, city)
  • LIBRARY_CARD(card_no PK, issue_date, expiry_date)
  • COPY (weak entity)(copy_no partial key, shelf_location, condition), identified by the owning BOOK (identifying relationship HAS_COPY, double rectangle/diamond)

Relationships:

  • MEMBER 1 : 1 LIBRARY_CARD (HOLDS): each member holds exactly one card, each card belongs to one member.
  • PUBLISHER 1 : N BOOK (PUBLISHES): a publisher publishes many books, each book has one publisher.
  • BOOK M : N AUTHOR (WRITTEN_BY): a book has many authors and an author writes many books.
  • BOOK 1 : N COPY (HAS_COPY, identifying, total participation of COPY): a book has many physical copies; a copy cannot exist without its book.
  • MEMBER M : N COPY (BORROWS, attributes issue_date, due_date, return_date): a member borrows many copies over time and a copy is borrowed by many members over time.

(b) Conversion to relational tables

  • MEMBER(<u>member_id</u>, name, address, phone)
  • LIBRARY_CARD(<u>card_no</u>, issue_date, expiry_date, member_id) with member_id FK to MEMBER, UNIQUE (1:1)
  • PUBLISHER(<u>pub_id</u>, name, city)
  • BOOK(<u>isbn</u>, title, price, edition, pub_id) with pub_id FK to PUBLISHER (1:N, key on the many side)
  • AUTHOR(<u>author_id</u>, name, country)
  • BOOK_AUTHOR(<u>isbn</u>, <u>author_id</u>) with both FKs (M:N relationship table)
  • COPY(<u>isbn</u>, <u>copy_no</u>, shelf_location, condition) with isbn FK to BOOK (weak entity: PK is owner key plus partial key)
  • BORROWS(<u>member_id</u>, <u>isbn</u>, <u>copy_no</u>, <u>issue_date</u>, due_date, return_date) with member_id FK to MEMBER and (isbn, copy_no) FK to COPY (M:N relationship table)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2021 · 10 marks

Define stored procedures and triggers. How they are applicable in database? Illustrate with examples, how can you create before and after triggers on INSERT query.

Answer

Stored procedure. A stored procedure is a named, precompiled group of SQL (and procedural) statements stored in the database and executed on demand with CALL. It can take input/output parameters.

Trigger. A trigger is a special stored program that is executed automatically by the DBMS when a specified event (INSERT, UPDATE, DELETE) occurs on a table, either BEFORE or AFTER the event. It cannot be called directly and takes no parameters.

Applications in a database.

  • Stored procedures: reuse of business logic, reduced network traffic, faster execution (precompiled), better security (users get EXECUTE rights without table access), consistency of operations.
  • Triggers: enforcing complex integrity rules, validating or modifying incoming data, auditing and logging changes, maintaining derived/summary data, and cascading actions.

Stored procedure example (MySQL).

DELIMITER //
CREATE PROCEDURE GetStudentsByDept(IN dept VARCHAR(30))
BEGIN
    SELECT * FROM Student WHERE department = dept;
END //
DELIMITER ;

CALL GetStudentsByDept('BCA');

BEFORE INSERT trigger (validate/modify data before it is stored):

CREATE TRIGGER before_student_insert
BEFORE INSERT ON Student
FOR EACH ROW
BEGIN
    IF NEW.marks < 0 THEN
        SET NEW.marks = 0;
    END IF;
    SET NEW.name = UPPER(NEW.name);
END;

AFTER INSERT trigger (record an audit entry once the row is inserted):

CREATE TRIGGER after_student_insert
AFTER INSERT ON Student
FOR EACH ROW
BEGIN
    INSERT INTO Student_Log(student_id, action, action_time)
    VALUES (NEW.id, 'INSERTED', NOW());
END;

NEW refers to the row being inserted. A BEFORE trigger can change NEW values; an AFTER trigger sees the committed row and is used for logging and side effects.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2022 · 5 marks

What is DBMS? Describe the advantages and disadvantages of using DBMS.

Answer

DBMS. A Database Management System is software that lets users define, create, store, retrieve, update and control access to a database, which is an organised collection of related data. Examples: MySQL, Oracle, PostgreSQL, SQL Server.

Advantages

  • Reduced data redundancy and inconsistency: data is stored centrally, not duplicated across files.
  • Data sharing: many users and applications can access the same data concurrently.
  • Data integrity: integrity constraints (keys, checks) keep data valid.
  • Security: authentication and authorisation restrict who can see or change data.
  • Backup and recovery: the system restores data after failures.
  • Data independence: programs are insulated from changes in storage structure.
  • Concurrency control and transactions: ACID properties keep multi-user access correct.
  • Standard query language: SQL gives easy ad-hoc querying.

Disadvantages

  • High cost: software, hardware and trained staff (DBA) are expensive.
  • Complexity: design and administration are complex.
  • Performance overhead: generality makes it slower than a tailor-made file system for simple tasks.
  • Single point of failure: a failure of the centralised DBMS affects all applications.
  • Large size and resource needs: needs considerable memory and disk space.
  • Conversion cost: migrating from an existing file system is difficult and costly.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2022 · 5 marks

Describe 3-schema architecture of database.

Answer

The three-schema (ANSI/SPARC) architecture separates the user view of the database from its physical storage. It has three levels:

  1. External level (view level): the highest level. It describes the part of the database relevant to each user or application group as external schemas (views). Different users see different views and hidden data is not shown, which also gives security.
  2. Conceptual level (logical level): describes the whole database for the community of users: entities, attributes, relationships, data types and constraints. There is one conceptual schema, independent of physical storage details. The DBA works at this level.
  3. Internal level (physical level): describes how data is physically stored: file structures, indexes, access paths, record placement, compression.

Mappings. The DBMS maps requests between levels: external/conceptual mapping and conceptual/internal mapping.

Data independence.

  • Logical data independence: the conceptual schema can change (add an attribute) without changing external schemas or programs.
  • Physical data independence: the internal schema can change (new index, different file organisation) without changing the conceptual schema.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2022 · 5 marks

What are roles and responsibilities of DBA.

Answer

The Database Administrator (DBA) is the person (or team) with central control over the DBMS and the data it holds.

Roles and responsibilities

  • Schema definition: creating the original database schema using DDL.
  • Storage structure and access method definition: choosing file organisation, indexes and access paths.
  • Schema and physical organisation modification: altering the schema or storage as requirements change.
  • Granting authorisation: creating user accounts and giving access rights, enforcing security policy.
  • Integrity checking: specifying integrity constraints and ensuring data quality.
  • Backup and recovery: regular backups, and recovery plans after hardware or software failure.
  • Performance monitoring and tuning: watching response times, optimising queries, indexing, and resource use.
  • Concurrency and deadlock management: making sure multiple users can work correctly.
  • Liaison with users: gathering requirements, training users and helping developers.
  • Capacity planning and upgrades: installing and upgrading DBMS software and hardware.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2022 · 5 marks

What are the states of transaction model? Describe the ACID properties of transaction.

Answer

States of a transaction

  • Active: the initial state; the transaction is executing.
  • Partially committed: the final statement has been executed, but the changes may not yet be on disk.
  • Committed: the transaction completed successfully and its changes are permanent.
  • Failed: normal execution cannot continue because of an error.
  • Aborted: the transaction has been rolled back and the database restored to its state before the transaction; it may then be restarted or terminated.

Flow: Active → Partially committed → Committed; Active/Partially committed → Failed → Aborted.

ACID properties

  • Atomicity: all operations of a transaction happen, or none do. If a failure occurs midway, all changes are rolled back (handled by the recovery manager).
  • Consistency: a transaction takes the database from one consistent state to another, preserving all integrity constraints. For a transfer of Rs 500 from A to B, the sum A+BA+B stays unchanged.
  • Isolation: concurrent transactions behave as if executed one after another; intermediate results are invisible to others (concurrency control).
  • Durability: once committed, the changes survive any later system failure (ensured by logs and recovery).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2022 · 5 marks

Describe the use of ER diagram. Draw an ER diagram for a university to design a database for it.

Answer

Use of an ER diagram. An Entity-Relationship diagram is a graphical conceptual model of the data. It is used to:

  • Model the real-world entities, their attributes and relationships before implementation.
  • Communicate the design between designers, developers and non-technical users.
  • Specify keys, cardinalities and participation constraints.
  • Serve as the basis for converting to relational tables.

ER diagram for a university (rectangles = entities, ellipses = attributes, diamonds = relationships):

Entities and attributes:

  • STUDENT(student_id PK, name, address, dob)
  • COURSE(course_id PK, title, credit_hours)
  • TEACHER(teacher_id PK, name, qualification, salary)
  • DEPARTMENT(dept_id PK, dept_name, location)

Relationships:

  • DEPARTMENT 1 : N STUDENT (ENROLLED_IN): a department has many students; each student belongs to one department (total participation of student).
  • DEPARTMENT 1 : N TEACHER (WORKS_FOR).
  • DEPARTMENT 1 : N COURSE (OFFERS).
  • STUDENT M : N COURSE (REGISTERS, attributes: semester, grade).
  • TEACHER M : N COURSE (TEACHES) or 1:N if each course has one teacher.
  • TEACHER 1 : 1 DEPARTMENT (HEADS): one teacher heads a department.

Draw each entity as a rectangle with its key attribute underlined, connect each pair through a diamond, and mark the cardinalities (1, N, M) on the connecting lines.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2022 · 10 marks

Define normalization. Describe the importance of normalization in DBMS. Describe 1NF, 2NF and 3NF with examples.

Answer

Normalization. Normalization is the process of organising the attributes and tables of a relational database, using functional dependencies, to minimise redundancy and avoid insertion, update and deletion anomalies. A large table is decomposed into smaller well-structured tables, without losing information.

Importance

  • Removes data redundancy and saves storage.
  • Prevents insertion, update and deletion anomalies.
  • Keeps data consistent and improves integrity.
  • Makes the schema easier to maintain and extend.

First Normal Form (1NF). A relation is in 1NF if every attribute holds only atomic (indivisible) values, with no repeating groups or multivalued attributes.

Not in 1NF: Student(Roll, Name, Phone) with Phone = {9841.., 9851..}. In 1NF: Student(Roll, Name, Phone) with one phone number per row: (1, Ram, 9841..), (1, Ram, 9851..), with key (Roll, Phone).

Second Normal Form (2NF). A relation is in 2NF if it is in 1NF and no non-prime attribute is partially dependent on a part of a composite candidate key.

Example: Enroll(StudentID, CourseID, StudentName, Grade), key (StudentID, CourseID). Here StudentID → StudentName is a partial dependency. Decompose:

  • Student(StudentID, StudentName)
  • Enroll(StudentID, CourseID, Grade)

Third Normal Form (3NF). A relation is in 3NF if it is in 2NF and no non-prime attribute is transitively dependent on the key (for every FD X→AX \rightarrow A, either XX is a superkey or AA is a prime attribute).

Example: Student(StudentID, Name, DeptID, DeptName) with StudentID → DeptID → DeptName (transitive). Decompose:

  • Student(StudentID, Name, DeptID)
  • Department(DeptID, DeptName)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2022 · 10 marks

Differentiate between stored procedure and trigger. Why concurrency control is needed? Describe timestamp based concurrency protocol.

Answer

Stored procedure vs trigger

BasisStored procedureTrigger
InvocationCalled explicitly with CALL/EXECFires automatically on INSERT, UPDATE or DELETE
ParametersAccepts input and output parametersTakes no parameters
Return valueMay return values/result setsReturns nothing
Transaction controlCan use COMMIT/ROLLBACKRuns within the triggering statement's transaction
PurposeReusable business logic, batch operationsEnforcing rules, auditing, maintaining derived data
ScopeIndependent of a tableTied to a specific table and event

Why concurrency control is needed. When many transactions execute at the same time, uncontrolled interleaving can cause:

  • Lost update: two transactions overwrite each other's updates.
  • Dirty read: a transaction reads data written by an uncommitted transaction that later aborts.
  • Unrepeatable read: a repeated read in one transaction returns different values.
  • Incorrect summary / phantom: aggregates see partial updates.

Concurrency control ensures isolation and serializability, so that the database stays consistent while throughput is maintained.

Timestamp-based protocol. Each transaction TiT_i gets a unique timestamp TS(Ti)TS(T_i) when it starts (older = smaller). Each data item QQ keeps:

  • W-TS(Q)W\text{-}TS(Q): the largest timestamp of any transaction that successfully wrote QQ.
  • R-TS(Q)R\text{-}TS(Q): the largest timestamp of any transaction that successfully read QQ.

Rules:

  • TiT_i issues read(Q):
    • If TS(Ti)<W-TS(Q)TS(T_i) < W\text{-}TS(Q), it would read an already-overwritten value, so the read is rejected and TiT_i is rolled back.
    • Otherwise, the read executes and R-TS(Q)=max⁡(R-TS(Q),TS(Ti))R\text{-}TS(Q) = \max(R\text{-}TS(Q), TS(T_i)).
  • TiT_i issues write(Q):
    • If TS(Ti)<R-TS(Q)TS(T_i) < R\text{-}TS(Q), a younger transaction already read the value that would be overwritten, so the write is rejected and TiT_i is rolled back.
    • If TS(Ti)<W-TS(Q)TS(T_i) < W\text{-}TS(Q), the write is obsolete, so it is rejected and TiT_i is rolled back (Thomas' write rule would simply ignore it).
    • Otherwise, the write executes and W-TS(Q)=TS(Ti)W\text{-}TS(Q) = TS(T_i).

A rolled-back transaction is restarted with a new timestamp. The protocol guarantees conflict-serializable schedules in timestamp order and is deadlock-free, since no transaction waits.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2022 · 10 marks

What is data model? What are its types? Describe the structure of database.

Answer

Data model. A data model is a collection of concepts and tools for describing the data, data relationships, data semantics and consistency constraints of a database. It provides the means to achieve abstraction of the database structure.

Types of data models

  1. Conceptual (high-level) models: close to the way users perceive data, e.g. the Entity-Relationship (ER) model and object-based models.
  2. Representational (record-based / implementation) models: hide some storage detail but can be implemented directly:
    • Hierarchical model: data in tree structure with parent-child links (1:N).
    • Network model: graph structure where a child can have several parents (M:N through sets).
    • Relational model: data in tables (relations) of rows and columns; most widely used.
  3. Physical (low-level) models: describe how data is stored in files, with record formats, orderings and access paths.

Other models: object-oriented, object-relational, semi-structured (XML/JSON), document and graph models.

Structure of a database. A database is organised as:

  • Tables (relations): each representing an entity set, made of rows (tuples/records) and columns (attributes/fields).
  • Schema: the logical design, including attribute names, data types, keys and constraints (primary key, foreign key).
  • Instance: the data stored at a given moment.
  • Indexes, views and metadata (data dictionary) to speed access, present user-specific data, and describe the data itself.

Overall, the DBMS structure follows the three-schema architecture (external, conceptual and internal levels), and has components such as the DDL/DML compilers, query processor, storage manager, transaction manager and buffer manager.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 5 marks

Define database and DBMS. Explain the benefits of DBMS in detail.

Answer

Database. A database is an organised collection of logically related data, stored so that it can be easily accessed, managed and updated. It represents some part of the real world, e.g. a college's students and courses.

DBMS. A Database Management System is software that creates, stores, retrieves, updates and controls access to the database, and acts as an interface between users/applications and the data. Examples: MySQL, Oracle, SQL Server, PostgreSQL.

Benefits of a DBMS

  • Controlled redundancy: data is stored once, saving space and avoiding inconsistency.
  • Data consistency and integrity: constraints (primary key, foreign key, check) keep data accurate and valid.
  • Data sharing: multiple users and applications access the same data simultaneously.
  • Data independence: changes in storage or logical structure do not require rewriting application programs.
  • Security: user authentication, access privileges and views restrict unauthorised access.
  • Backup and recovery: logs and backups restore the database after a crash.
  • Concurrency control: transaction management with ACID properties lets many users work safely.
  • Efficient querying: SQL, indexing and query optimisation give fast retrieval.
  • Standards and decision support: uniform standards, and better, timely information for decision making.
  • Reduced application development time through common services.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 5 marks

What are different SQL constraints to specify the rules for the data in the database? Explain.

Answer

SQL constraints are rules applied to table columns to limit the type of data that can be stored, ensuring accuracy and integrity.

  • NOT NULL: the column cannot hold NULL values.
  • UNIQUE: all values in the column (or column set) are distinct; NULL is allowed.
  • PRIMARY KEY: uniquely identifies each row; combines NOT NULL and UNIQUE; only one per table.
  • FOREIGN KEY: a column referencing the primary key of another table; keeps referential integrity (with ON DELETE/ON UPDATE actions).
  • CHECK: restricts values by a condition, e.g. age >= 18.
  • DEFAULT: supplies a default value when none is given.

Example:

CREATE TABLE Student (
    id      INT PRIMARY KEY,
    name    VARCHAR(50) NOT NULL,
    email   VARCHAR(80) UNIQUE,
    age     INT CHECK (age >= 16),
    country VARCHAR(20) DEFAULT 'Nepal',
    dept_id INT,
    FOREIGN KEY (dept_id) REFERENCES Department(dept_id)
);

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 5 marks

What is relational algebra? Explain different RA operations.

Answer

Relational algebra. Relational algebra is a procedural query language consisting of a set of operations that take one or two relations as input and produce a new relation as output. It is the theoretical foundation of SQL.

Fundamental operations

  • Selection (σ\sigma): selects rows satisfying a condition. σage>20(Student)\sigma_{age>20}(Student).
  • Projection (π\pi): selects specified columns and removes duplicates. πname,age(Student)\pi_{name,age}(Student).
  • Union (∪\cup): all tuples in RR or SS or both; relations must be union-compatible. R∪SR \cup S.
  • Set difference (−-): tuples in RR but not in SS. R−SR - S.
  • Cartesian product (×\times): every tuple of RR combined with every tuple of SS. R×SR \times S.
  • Rename (ρ\rho): renames a relation or attributes. ρS(a,b)(R)\rho_{S(a,b)}(R).

Additional operations

  • Intersection (∩\cap): tuples in both RR and SS.
  • Join (⋈\bowtie): combines related tuples; theta join with an arbitrary condition, equi-join with equality, natural join on common attributes, and outer joins (left, right, full) that keep unmatched tuples. R⋈R.a=S.aS=σR.a=S.a(R×S)R \bowtie_{R.a=S.a} S = \sigma_{R.a=S.a}(R \times S).
  • Division (÷\div): tuples of RR associated with all tuples of SS, e.g. students who have taken all courses.
  • Aggregation (G\mathcal{G}): functions like SUM, AVG, COUNT, MAX, MIN with grouping.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 5 marks

How candidate key is different from primary key? Also explain foreign key in detail.

Answer

Candidate key vs primary key

  • A candidate key is any minimal set of attributes that uniquely identifies every tuple of a relation. A relation can have several candidate keys.
  • The primary key is the one candidate key chosen by the designer to identify tuples. There is exactly one per relation, and it cannot be NULL.
Candidate keyPrimary key
Many per relationOnly one per relation
May allow NULL (unless declared otherwise)Never NULL
Alternatives to the primary key are called alternate keysSelected from the candidate keys

Example: in Student(RollNo, Email, Name), both RollNo and Email are candidate keys; RollNo is chosen as the primary key and Email is an alternate key.

Foreign key. A foreign key is an attribute (or set of attributes) in one relation (the referencing/child table) whose values must match the primary key (or a candidate key) of another relation (the referenced/parent table), or be NULL. It links tables and enforces referential integrity: a child row cannot refer to a non-existent parent row.

CREATE TABLE Department (dept_id INT PRIMARY KEY, dname VARCHAR(30));
CREATE TABLE Student (
    roll INT PRIMARY KEY,
    name VARCHAR(40),
    dept_id INT,
    FOREIGN KEY (dept_id) REFERENCES Department(dept_id)
        ON DELETE CASCADE ON UPDATE CASCADE
);

The referential actions (CASCADE, SET NULL, RESTRICT) define what happens to child rows when a parent row is deleted or updated. A foreign key may repeat in the child table, and a table can have several foreign keys.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 5 marks

What is a stored procedure? How can it be used in a database? Explain with an example.

Answer

Stored procedure. A stored procedure is a named, precompiled set of SQL statements (with control-flow logic) stored in the database server and executed by calling its name. It may take input (IN), output (OUT) or input-output (INOUT) parameters.

Use in a database

  • Encapsulates business logic once so many applications can reuse it.
  • Reduces network traffic, since one call replaces many statements.
  • Faster, because it is compiled and cached.
  • Improves security: users can be granted EXECUTE permission without direct table access.
  • Easier maintenance: change the logic in one place.

Example (MySQL). Add a new student and return the total count:

DELIMITER //
CREATE PROCEDURE AddStudent(IN p_id INT, IN p_name VARCHAR(50), OUT total INT)
BEGIN
    INSERT INTO Student(id, name) VALUES (p_id, p_name);
    SELECT COUNT(*) INTO total FROM Student;
END //
DELIMITER ;

CALL AddStudent(101, 'Sita', @cnt);
SELECT @cnt;

To remove it: DROP PROCEDURE AddStudent;

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 5 marks

What are the major purposes of concurrency control? Explain two phase locking protocol in detail.

Answer

Purposes of concurrency control

  • Ensure isolation and consistency when transactions run concurrently.
  • Prevent problems such as lost update, dirty read, unrepeatable read and phantom.
  • Guarantee serializable schedules, equivalent to some serial execution.
  • Allow high throughput and resource use while avoiding interference.
  • Avoid or handle deadlocks and maintain database integrity.

Two-phase locking (2PL) protocol. Each transaction acquires and releases locks in two distinct phases:

  1. Growing phase: the transaction may obtain locks (shared lock-S for reading, exclusive lock-X for writing) but may not release any.
  2. Shrinking phase: the transaction may release locks but cannot obtain any new lock.

The point at which a transaction obtains its final lock is the lock point. Once it releases its first lock, it enters the shrinking phase.

Lock compatibility: S is compatible with S only; X conflicts with S and X. Lock upgrade (S to X) is allowed in the growing phase and downgrade in the shrinking phase.

Properties

  • 2PL guarantees conflict serializability; transactions can be serialized in lock-point order.
  • It does not prevent deadlock, and does not avoid cascading rollbacks.

Variants

  • Strict 2PL: holds all exclusive locks until commit/abort, so avoiding cascading rollbacks.
  • Rigorous 2PL: holds all locks (shared and exclusive) until commit/abort.
  • Conservative 2PL: acquires all locks before starting, so it is deadlock-free.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 5 marks

What is database security? Describe steps of query processing.

Answer

Database security. Database security means protecting the database against threats to its confidentiality, integrity and availability, through measures that prevent unauthorised access, modification, destruction or disclosure of data. It is implemented using:

  • Authentication (user ID/password) and authorisation (privileges via GRANT/REVOKE).
  • Access control (discretionary and mandatory), views to hide data.
  • Encryption of stored and transmitted data.
  • Auditing and logging, backups, and firewalls.
  • Protection against threats such as SQL injection.

Steps of query processing

  1. Parsing and translation: the query is checked for syntax, validated against the data dictionary (tables, columns, privileges), and converted into an internal form, i.e. a relational algebra expression/parse tree.
  2. Optimization: the optimizer generates alternative equivalent evaluation plans (e.g. different join orders, index use), estimates their cost (disk I/O, CPU) using statistics, and selects the cheapest plan.
  3. Evaluation (execution): the query execution engine runs the chosen plan, accessing the stored data through the storage manager, and returns the result to the user.

Flow: SQL query → Parser/Translator → Relational algebra → Optimizer (with statistics) → Execution plan → Evaluation engine → Output.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 10 marks

What are fully and partial functional dependencies? Explain 2NF and 3NF in detail.

Answer

(a) Functional dependencies. A functional dependency X→YX \rightarrow Y means that each value of XX determines exactly one value of YY.

  • Fully functional dependency: YY depends on the whole of a composite key XX and on no proper subset of it. For example, in Enrol(StudentID,CourseID‾,Grade)\text{Enrol}(\underline{StudentID, CourseID}, Grade), {StudentID,CourseID}→Grade\{StudentID, CourseID\} \rightarrow Grade is full, because neither attribute alone determines the grade.
  • Partial functional dependency: YY depends on only a part of a composite candidate key. For example, in Enrol(StudentID,CourseID‾,Grade,StudentName)\text{Enrol}(\underline{StudentID, CourseID}, Grade, StudentName), StudentID→StudentNameStudentID \rightarrow StudentName is partial, because the name depends on just one part of the key.

(b) Second Normal Form (2NF). A relation is in 2NF if it is in 1NF (atomic values only) and every non-prime attribute is fully functionally dependent on every candidate key, so there are no partial dependencies. Only relations with a composite key can violate 2NF.

Example: R(StudentID,CourseID‾,StudentName,CourseTitle,Grade)R(\underline{StudentID, CourseID}, StudentName, CourseTitle, Grade) with StudentID→StudentNameStudentID \rightarrow StudentName and CourseID→CourseTitleCourseID \rightarrow CourseTitle.

Both are partial dependencies, so we decompose:

  • Student(StudentID‾,StudentName)Student(\underline{StudentID}, StudentName)
  • Course(CourseID‾,CourseTitle)Course(\underline{CourseID}, CourseTitle)
  • Enrol(StudentID,CourseID‾,Grade)Enrol(\underline{StudentID, CourseID}, Grade)

This removes the update, insertion and deletion anomalies caused by repeating names and titles.

(c) Third Normal Form (3NF). A relation is in 3NF if it is in 2NF and no non-prime attribute is transitively dependent on a candidate key. Equivalently, for every non-trivial dependency X→AX \rightarrow A, either XX is a super key or AA is a prime attribute.

Example: Employee(EmpID‾,EmpName,DeptID,DeptName)Employee(\underline{EmpID}, EmpName, DeptID, DeptName) with EmpID→DeptIDEmpID \rightarrow DeptID and DeptID→DeptNameDeptID \rightarrow DeptName. Here EmpID→DeptNameEmpID \rightarrow DeptName holds only transitively through DeptIDDeptID, so we decompose:

  • Employee(EmpID‾,EmpName,DeptID)Employee(\underline{EmpID}, EmpName, DeptID)
  • Department(DeptID‾,DeptName)Department(\underline{DeptID}, DeptName)

Each fact is now stored once, and the decomposition is lossless and dependency preserving.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 10 marks

How different join operations can be performed? Explain with proper examples. Consider a database of a shipment company. Shipped items are received into the system at a single retail center. Shipped items make their way to their destination via one or more standard transportation events (i.e. flights, truck deliveries). The transportation events follow a regular schedule. Create an ER diagram to represent this information.

Answer

(a) Join operations. A join combines rows of two tables on a condition. Take Student(SID,Name,DID)Student(SID, Name, DID) and Dept(DID,DName)Dept(DID, DName).

SIDNameDID
1RamD1
2SitaD2
3HariNULL
DIDDName
D1Computer
D2Science
D3Law
  • Inner join (equi/natural join): returns only matching rows. SELECT S.Name, D.DName FROM Student S INNER JOIN Dept D ON S.DID = D.DID; Result: (Ram, Computer), (Sita, Science).
  • Left outer join: all rows of the left table, with NULL for non-matches. The query above with LEFT JOIN gives the two rows plus (Hari, NULL).
  • Right outer join: all rows of the right table. It gives the two matches plus (NULL, Law).
  • Full outer join: all rows from both sides, so it gives all four rows above.
  • Cross join: the Cartesian product, which here has 3×3=93 \times 3 = 9 rows.
  • Self join: a table joined to itself using aliases, for example to find employees and their managers.
  • Natural join: an equi-join on all common attribute names, with the duplicate column dropped.

(b) ER diagram for the shipment company.

Entities and attributes:

  • RetailCenter (CenterID, Name, Address)
  • ShippedItem (ItemID, Weight, Description, ReceivedDate, DestinationAddress)
  • TransportationEvent (EventID, Type [flight/truck], ScheduledDeparture, ScheduledArrival, FromLocation, ToLocation). Because events follow a regular schedule, this entity can be seen as a Schedule entity of recurring services.

Relationships:

  • RetailCenter 1 --- receives --- N ShippedItem. Every item is received at the single center, so the participation of ShippedItem is total.
  • ShippedItem M --- travels_via --- N TransportationEvent. An item may use one or more events (total participation of item), and an event carries many items. The relationship attribute is LoadedDate or SequenceNo, which gives the order of the legs.
[RetailCenter]--1--<receives>==N==[ShippedItem]==M--<travels_via>--N--[TransportationEvent]

Here == denotes total participation and -- denotes partial participation. Since there is a single retail center, receives may be dropped in a simplified model, and ShippedItem then becomes the main entity linked to TransportationEvent.

Mapping to relations:

  • ShippedItem(ItemID, ..., CenterID FK)
  • TransportationEvent(EventID, ...)
  • Travels_via(ItemID FK, EventID FK, SequenceNo), with a composite key (ItemID,EventID)(ItemID, EventID).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2023 · 10 marks

Consider the following tables: Book(Bookid, Title, Publisher, Published Date, Price)
Book_Authors (Bookid, Author name)
Borrower (Card No, Name, Address, Contact)
Bookissue (BookId, CardNo, IssuedDate, Due Date)
Write SQL query for the following:
a) Find the name of the books taken by Ramesh Sharma.
b) Find the Issued book name and the borrower's name who have Issued date before 15th May, 2023 and due date after 15th June, 2023.
c) Find the borrower's name who has taken the book written by Laxmi Prashad Devkota.
d) Find the number of books Issued on the date 25th April, 2023.

Answer

Tables: Book(Bookid, Title, Publisher, PublishedDate, Price), Book_Authors(Bookid, AuthorName), Borrower(CardNo, Name, Address, Contact), Bookissue(BookId, CardNo, IssuedDate, DueDate).

(a) Books taken by Ramesh Sharma

SELECT B.Title
FROM Book B
JOIN Bookissue I ON B.Bookid = I.BookId
JOIN Borrower R ON I.CardNo = R.CardNo
WHERE R.Name = 'Ramesh Sharma';

(b) Issued book name and borrower's name, issued before 15 May 2023 and due after 15 June 2023

SELECT B.Title, R.Name
FROM Bookissue I
JOIN Book B ON B.Bookid = I.BookId
JOIN Borrower R ON R.CardNo = I.CardNo
WHERE I.IssuedDate < '2023-05-15'
  AND I.DueDate > '2023-06-15';

(c) Borrowers who have taken a book written by Laxmi Prashad Devkota

SELECT DISTINCT R.Name
FROM Borrower R
JOIN Bookissue I ON R.CardNo = I.CardNo
JOIN Book_Authors A ON A.Bookid = I.BookId
WHERE A.AuthorName = 'Laxmi Prashad Devkota';

(d) Number of books issued on 25 April 2023

SELECT COUNT(*) AS BooksIssued
FROM Bookissue
WHERE IssuedDate = '2023-04-25';

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 5 marks

Define database system. Write the merits and demerits of DBMS.

Answer

Database system. A database system is a collection of interrelated, persistent data (the database) together with the database management system (DBMS) software that is used to define, store, retrieve, secure and manage that data, and the application programs that use it. The DBMS acts as the interface between users and the stored data. Examples of DBMSs are MySQL, Oracle, PostgreSQL and SQL Server.

Merits of DBMS

  • Reduced data redundancy and inconsistency, since data is stored centrally.
  • Data sharing among many users and applications.
  • Data independence, so that structure changes do not affect programs.
  • Data integrity through constraints.
  • Security through authorization and access control.
  • Concurrency control, so many users can work together safely.
  • Backup and recovery after failures.
  • Standard query language (SQL) for easy retrieval, and enforcement of standards.

Demerits of DBMS

  • High cost of software, hardware and trained personnel.
  • Complexity of design and administration.
  • Large size, requiring more memory and storage.
  • Performance overhead for simple applications compared with file processing.
  • A central failure can affect all users, so there is a higher impact of failure.
  • Conversion from existing file systems is costly and time consuming.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 5 marks

Draw and explain three schema architecture of the database system.

Answer

Three schema architecture (ANSI/SPARC). It separates the user view of data from the physical storage in three levels, which supports data independence.

  External level   [View 1] [View 2] ... [View n]
                        |  external/conceptual mapping
  Conceptual level      [ Conceptual schema ]
                        |  conceptual/internal mapping
  Internal level        [ Internal (physical) schema ]
                        |
                    Stored database
  1. External (view) level: the highest level. It describes the part of the database relevant to each user group through many external schemas (views), and hides the rest of the data. A teacher may see only marks and a student only their own record.
  2. Conceptual (logical) level: one conceptual schema that describes the whole database for the community of users: entities, attributes, relationships, data types and constraints. It hides physical storage details and is designed by the DBA.
  3. Internal (physical) level: describes how the data is physically stored, including file organization, indexes, access paths, record placement and compression.

Mappings convert between levels, so a request on a view is translated to the conceptual schema and then to the stored data.

Data independence:

  • Logical data independence is the ability to change the conceptual schema without changing the external schemas.
  • Physical data independence is the ability to change the internal schema without changing the conceptual schema.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 5 marks

What are an entity and its attributes? Write the difference between a strong and weak entity set with an example.

Answer

Entity. An entity is a real-world object that can be distinctly identified, such as a student, employee, course or book. A collection of similar entities forms an entity set.

Attributes. Attributes are the properties that describe an entity. For example, the entity Student has attributes RollNo, Name, Address and DOB. Attributes can be:

  • simple or composite (Name = First + Last),
  • single-valued or multi-valued (PhoneNo),
  • stored or derived (Age from DOB),
  • key attributes, which uniquely identify the entity.

Strong versus weak entity set

BasisStrong entity setWeak entity set
KeyHas its own primary keyHas no primary key of its own, only a partial key (discriminator)
ExistenceExists independentlyDepends on an owner (identifying) entity
RelationshipConnected by an ordinary relationshipConnected by an identifying relationship
ParticipationParticipation may be partial or totalTotal participation in the identifying relationship
NotationSingle rectangleDouble rectangle, with a double diamond for the relationship

Example: Employee (strong, key EmpID) and Dependent (weak). Dependent has only the partial key DependentName, and is identified by combining it with the owner's EmpID. The primary key is therefore (EmpID,DependentName)(EmpID, DependentName). If the employee is deleted, the dependents are deleted too.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 5 marks

Why integrity constraints are used in databases? Explain different types of integrity constraints with examples.

Answer

Why integrity constraints are used. Integrity constraints are rules enforced by the DBMS to keep the data accurate, valid and consistent. They prevent invalid data entering the database, whether through user error or application bugs, and preserve the correct relationships between tables.

Types of integrity constraints

  1. Domain constraint: the value of an attribute must come from its domain (data type, range, format). Example: Age INT CHECK (Age >= 0 AND Age <= 120).
  2. Entity integrity: the primary key cannot be NULL and must be unique. Example: RollNo in Student.
  3. Referential integrity: a foreign key value must match an existing primary key value in the referenced table, or be NULL. Example: Student.DeptID must exist in Department.DeptID.
  4. Key (uniqueness) constraint: no two tuples have the same value for the key, as with UNIQUE (Email).
  5. NOT NULL constraint: a column must always have a value.
  6. Semantic/business rules: enforced with CHECK constraints or triggers.
CREATE TABLE Department (
  DeptID INT PRIMARY KEY,
  DName  VARCHAR(30) NOT NULL UNIQUE
);
CREATE TABLE Student (
  RollNo INT PRIMARY KEY,
  Name   VARCHAR(40) NOT NULL,
  Age    INT CHECK (Age >= 15),
  DeptID INT,
  FOREIGN KEY (DeptID) REFERENCES Department(DeptID)
);

Inserting a student with a non-existent DeptID, or with a duplicate RollNo, is rejected by the DBMS.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 5 marks

What is functional dependency? Explain its types with examples.

Answer

Functional dependency (FD). An FD X→YX \rightarrow Y between sets of attributes of a relation means that whenever two tuples agree on XX, they must agree on YY. That is, XX uniquely determines YY. For example, RollNo→NameRollNo \rightarrow Name.

Types of functional dependency

  1. Trivial FD: X→YX \rightarrow Y where Y⊆XY \subseteq X, for example {RollNo,Name}→Name\{RollNo, Name\} \rightarrow Name. Non-trivial FD: Y⊈XY \not\subseteq X, for example RollNo→NameRollNo \rightarrow Name.
  2. Fully functional dependency: YY depends on all of XX and not on any proper subset of XX. For example, {StudentID,CourseID}→Grade\{StudentID, CourseID\} \rightarrow Grade.
  3. Partial dependency: YY depends on a proper subset of the key. For example, with key {StudentID,CourseID}\{StudentID, CourseID\}, StudentID→StudentNameStudentID \rightarrow StudentName.
  4. Transitive dependency: if X→YX \rightarrow Y and Y→ZY \rightarrow Z (and Y↛XY \not\rightarrow X), then X→ZX \rightarrow Z holds transitively. For example, EmpID→DeptID→DeptNameEmpID \rightarrow DeptID \rightarrow DeptName.
  5. Multivalued dependency (X↠YX \twoheadrightarrow Y): XX determines a set of values of YY independently of the other attributes. For example, Course↠TeacherCourse \twoheadrightarrow Teacher and Course↠BookCourse \twoheadrightarrow Book in a Course-Teacher-Book relation.

FDs are used to find keys and to normalize relations (2NF, 3NF, BCNF).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 5 marks

Differentiate between discretionary access control and mandatory access control with example.

Answer

Discretionary access control (DAC). Access is granted at the discretion of the owner of an object. The owner (or a user with grant option) decides who gets which privileges, and can pass the privileges on to others. It is flexible and implemented with GRANT and REVOKE.

Example: GRANT SELECT, UPDATE ON Student TO ram WITH GRANT OPTION; Ram can now also grant these rights to another user.

Mandatory access control (MAC). Access is decided by the system according to security classifications. Objects are given classes (Top Secret, Secret, Confidential, Unclassified) and users are given clearances. The Bell-LaPadula rules apply: a subject may read an object only if its clearance is greater than or equal to the object's class (no read up), and may write only if the object's class is greater than or equal to its clearance (no write down). Owners cannot change these rules.

Example: in a defence database, a user with Confidential clearance cannot read Secret records, even if the owner wants to share them.

BasisDACMAC
Decision byOwner of the dataCentral authority, by policy
FlexibilityFlexibleRigid
SecurityLower (propagation of rights possible)Higher
Based onIdentity and privilegesSecurity labels and clearances
Used inCommercial systemsMilitary, government systems

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 5 marks

Write the ACID properties of transactions. Explain the concepts of serializability in database transactions.

Answer

ACID properties. A transaction is a logical unit of work, and the DBMS guarantees the following properties.

  • Atomicity: all operations of a transaction happen or none do. If a failure occurs midway, the changes are rolled back. Example: in a transfer of Rs 500 from A to B, either both the debit and the credit happen or neither does.
  • Consistency: a transaction takes the database from one consistent state to another, preserving integrity constraints. The total of A + B stays the same after the transfer.
  • Isolation: concurrent transactions do not interfere, and each appears to run alone. The intermediate state of one transaction is not visible to others.
  • Durability: once a transaction commits, its changes persist even after a system crash, through logs and recovery.

Serializability. A schedule (an interleaving of operations of concurrent transactions) is serializable if its effect is equal to that of some serial schedule, in which transactions run one after another. It guarantees correctness of concurrent execution.

  • Conflict serializability: a schedule is conflict serializable if it can be converted into a serial schedule by swapping non-conflicting operations. Two operations conflict if they belong to different transactions, access the same data item, and at least one is a write. It is tested with a precedence graph, with an edge Ti→TjT_i \rightarrow T_j for each conflict where TiT_i operates first. The schedule is conflict serializable if and only if the graph has no cycle.
  • View serializability: a schedule is view equivalent to a serial schedule if the initial reads, the read-from relationships and the final writes are the same. Every conflict serializable schedule is view serializable, but not the reverse.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 10 marks

Why normalization is required in database? Explain the 1NF, 2NF and 3NF of normalization with example.

Answer

Why normalization is required. Normalization organizes relations to remove redundancy and avoid the anomalies that come from it. Without it we get:

  • Update anomaly: the same fact must be changed in many rows, and missing one causes inconsistency.
  • Insertion anomaly: a fact cannot be recorded without unrelated data.
  • Deletion anomaly: deleting a row accidentally removes other facts.

It also saves storage and gives a cleaner design. It works by decomposing relations using functional dependencies.

First Normal Form (1NF). All attribute values are atomic, with no repeating groups or multivalued attributes.

Example: Student(RollNo,Name,Phones)Student(RollNo, Name, Phones) with Phones = "9841, 9851" is not in 1NF. We make it 1NF by giving one phone per row: Student(RollNo,Phone‾,Name)Student(\underline{RollNo, Phone}, Name).

Second Normal Form (2NF). The relation is in 1NF and there is no partial dependency of a non-prime attribute on part of a composite key.

Example: Enrol(RollNo,CourseID‾,StudentName,Grade)Enrol(\underline{RollNo, CourseID}, StudentName, Grade) with RollNo→StudentNameRollNo \rightarrow StudentName. Decompose into Student(RollNo‾,StudentName)Student(\underline{RollNo}, StudentName) and Enrol(RollNo,CourseID‾,Grade)Enrol(\underline{RollNo, CourseID}, Grade).

Third Normal Form (3NF). The relation is in 2NF and there is no transitive dependency of a non-prime attribute on a key.

Example: Employee(EmpID‾,Name,DeptID,DeptName)Employee(\underline{EmpID}, Name, DeptID, DeptName) with DeptID→DeptNameDeptID \rightarrow DeptName. Decompose into Employee(EmpID‾,Name,DeptID)Employee(\underline{EmpID}, Name, DeptID) and Department(DeptID‾,DeptName)Department(\underline{DeptID}, DeptName).

Each step is lossless, and the result stores every fact in exactly one place.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 10 marks

How participation constraints are used in ER diagram? Explain. Also 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 and has an associated due date, and the date when the payment was received.

Answer

Participation constraints. A participation constraint specifies whether every entity of an entity set must take part in a relationship set.

  • Total participation: every entity must participate in at least one relationship instance. It is drawn with a double line from the entity to the relationship. Example: every Employee must belong to a Department.
  • Partial participation: some entities may not participate. It is drawn with a single line. Example: not every Employee manages a Department.

Together with cardinality (1:1, 1:N, M:N), participation constraints show the minimum and maximum number of relationship instances an entity can have. A weak entity always participates totally in its identifying relationship.

E-R diagram for the car insurance company

Entities:

  • Customer (CustID, Name, Address, Phone)
  • Car (RegNo, Model, Year)
  • Accident (ReportNo, Date, Location, DamageAmount)
  • Policy (PolicyNo, StartDate, EndDate)
  • Payment (PaymentNo, PeriodFrom, PeriodTo, DueDate, ReceivedDate). This is a weak entity, identified through Policy.

Relationships:

[Customer] 1 ---<owns>=== N [Car]         (a car has an owner: total on Car)
[Car] 1 ---<involved_in>--- N [Accident]  (zero or more accidents: partial on Car)
[Policy] 1 ---<covers>=== N [Car]         (a policy covers one or more cars: total on Policy)
[Policy] 1 ===<has>=== N ((Payment))      (identifying; one or more payments: total on Policy)
  • A customer owns one or more cars, so Customer participates totally in owns.
  • A car has zero to many accidents, so participation in involved_in is partial on the Car side. An accident belongs to exactly one car.
  • A policy covers one or more cars (total on Policy), and each car is covered by one policy.
  • A policy has one or more premium payments (total), and Payment is a weak entity with the partial key PaymentNo (or DueDate), so its key is (PolicyNo,PaymentNo)(PolicyNo, PaymentNo).

Relational mapping: Car(RegNo, ..., CustID FK, PolicyNo FK), Accident(ReportNo, ..., RegNo FK), Payment(PolicyNo FK, PaymentNo, PeriodFrom, PeriodTo, DueDate, ReceivedDate).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2024 · 10 marks

Consider the following employee database, where primary keys are underlined Supplier (supplier-id, supplier-name, city) Suppliers (Supplier-id, parts-id, quantity) Parts (part-id, par-name, color, weight)
a) Write a SQL query to create above table.
b) Find the name of all suppliers who has supplied parts with quantity more than 100 and the name of all parts supplied by "RD Traders"
c) Find the number of parts supplied by "S02"
d) Find the name of suppliers located in city "KTM".

Answer

Tables: Supplier(supplier_id, supplier_name, city), Suppliers(supplier_id, parts_id, quantity), Parts(part_id, part_name, color, weight).

(a) Create the tables

CREATE TABLE Supplier (
  supplier_id   VARCHAR(10) PRIMARY KEY,
  supplier_name VARCHAR(50) NOT NULL,
  city          VARCHAR(30)
);

CREATE TABLE Parts (
  part_id   VARCHAR(10) PRIMARY KEY,
  part_name VARCHAR(50) NOT NULL,
  color     VARCHAR(20),
  weight    DECIMAL(8,2)
);

CREATE TABLE Suppliers (
  supplier_id VARCHAR(10),
  parts_id    VARCHAR(10),
  quantity    INT,
  PRIMARY KEY (supplier_id, parts_id),
  FOREIGN KEY (supplier_id) REFERENCES Supplier(supplier_id),
  FOREIGN KEY (parts_id)    REFERENCES Parts(part_id)
);

(b) Names of suppliers who supplied parts with quantity more than 100, and the names of all parts supplied by "RD Traders"

SELECT DISTINCT S.supplier_name
FROM Supplier S
JOIN Suppliers X ON S.supplier_id = X.supplier_id
WHERE X.quantity > 100;

SELECT P.part_name
FROM Parts P
JOIN Suppliers X ON P.part_id = X.parts_id
JOIN Supplier S  ON S.supplier_id = X.supplier_id
WHERE S.supplier_name = 'RD Traders';

(c) Number of parts supplied by "S02"

SELECT COUNT(parts_id) AS NumParts
FROM Suppliers
WHERE supplier_id = 'S02';

(d) Suppliers located in "KTM"

SELECT supplier_name
FROM Supplier
WHERE city = 'KTM';

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 5 marks

What is flat file system? Explain the advantages of using DBMS over flat file system.

Answer

Flat file system. A flat file system stores data in simple separate files (text, CSV or fixed-format records), usually one file per application, with no built-in relationships between files. Each application program defines and manages its own file structure, and the data are accessed by sequential or simple indexed methods.

Problems of flat files are redundancy, inconsistency, isolated data, program-data dependence, weak security and no concurrency control.

Advantages of DBMS over a flat file system

  1. Less redundancy and inconsistency: data are stored centrally and shared, rather than duplicated across files.
  2. Data independence: programs are not affected when file structure or storage changes.
  3. Easy and powerful retrieval: SQL answers ad hoc queries without writing new programs.
  4. Data integrity: constraints (keys, domain, referential) are enforced by the DBMS.
  5. Security: authorization and access control by user or view.
  6. Concurrent access: locking and transactions let many users work safely.
  7. Backup and recovery: logs and recovery restore data after a crash.
  8. Atomic updates: transactions give all-or-nothing behaviour.
  9. Relationships and sharing: data from many entities are linked and shared by many applications.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 5 marks

How logical data independence is different from physical data independence? Explain three level database architecture.

Answer

Logical versus physical data independence

BasisLogical data independencePhysical data independence
MeaningAbility to change the conceptual schema without changing external schemas or application programsAbility to change the internal schema without changing the conceptual schema
Examples of changeAdding or removing an attribute or entity, splitting a relationChanging file organization, adding an index, moving to another disk, changing the access method
Mapping affectedExternal/conceptual mappingConceptual/internal mapping
DifficultyHarder to achieveEasier to achieve

Three level database architecture

External level   : View 1 | View 2 | ... | View n
                      (external/conceptual mapping)
Conceptual level : Whole logical structure of the database
                      (conceptual/internal mapping)
Internal level   : Physical storage structure
  • External level: the view level. Each user group sees only the part of the database it needs, which also gives security.
  • Conceptual level: describes the entire database logically: entities, attributes, relationships, data types and constraints, independent of storage.
  • Internal level: describes physical storage, such as file structures, indexes, record formats and access paths.

The mappings between levels provide the two forms of data independence above.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 5 marks

How primary key is different from super key? Explain composite key and partial key.

Answer

Primary key versus super key

  • A super key is any set of one or more attributes that uniquely identifies a tuple. It may contain extra, unnecessary attributes. In Student(RollNo,Name,Email)Student(RollNo, Name, Email), the sets {RollNo}\{RollNo\}, {RollNo,Name}\{RollNo, Name\} and {Email,Name}\{Email, Name\} may be super keys.
  • A candidate key is a minimal super key, with no redundant attribute.
  • A primary key is the one candidate key chosen by the designer to identify tuples. It cannot be NULL or duplicated.

So every primary key is a super key, but not every super key is a primary key. There are many super keys of a relation, but only one primary key.

Composite key. A key made of two or more attributes that together identify a tuple uniquely, although none of them alone does. Example: Enrol(StudentID,CourseID‾,Grade)Enrol(\underline{StudentID, CourseID}, Grade) has the composite key (StudentID,CourseID)(StudentID, CourseID).

Partial key (discriminator). An attribute, or set of attributes, of a weak entity set that identifies the weak entities only among those related to the same owner entity. It is underlined with a dashed line. Example: for the weak entity Dependent of Employee, DependentName is the partial key, and the full key is (EmpID,DependentName)(EmpID, DependentName).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 5 marks

What are selection and projection operators in relational algebra? Given a table with schema Student(Rollno(PK), Fname, Lname, Address, Level, Did(FK)),
Department(Did(PK), Dname, HOD)
Write an RA query to find the name of students who are in 'Bachelor' level living in 'Birgunj' and studies under the department with department head 'Ramesh Sharma'.

Answer

Selection (σ\sigma). It selects the tuples (rows) of a relation that satisfy a condition: σcondition(R)\sigma_{condition}(R). Example: σLevel=′Bachelor′(Student)\sigma_{Level='Bachelor'}(Student) returns the bachelor students. The result has the same attributes as RR.

Projection (π\pi). It selects the given attributes (columns) of a relation and removes duplicate tuples: πA1,A2(R)\pi_{A_1, A_2}(R). Example: πFname,Lname(Student)\pi_{Fname, Lname}(Student).

Relational algebra query. The names of students at Bachelor level, living in Birgunj, whose department head is Ramesh Sharma:

πFname, Lname(σLevel=′Bachelor′ ∧ Address=′Birgunj′ ∧ HOD=′RameshSharma′(Student⋈Student.Did=Department.DidDepartment))\pi_{Fname,\,Lname}\Big(\sigma_{Level='Bachelor' \,\wedge\, Address='Birgunj' \,\wedge\, HOD='Ramesh Sharma'}\big(Student \bowtie_{Student.Did = Department.Did} Department\big)\Big)

Equivalently, selecting first and then joining:

πFname, Lname(σLevel=′Bachelor′ ∧ Address=′Birgunj′(Student)⋈σHOD=′RameshSharma′(Department))\pi_{Fname,\,Lname}\Big(\sigma_{Level='Bachelor' \,\wedge\, Address='Birgunj'}(Student) \bowtie \sigma_{HOD='Ramesh Sharma'}(Department)\Big)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 5 marks

How parameters can be passed to a stored procedure? Explain with an example.

Answer

Stored procedure. A stored procedure is a named, precompiled block of SQL statements stored in the database and executed with CALL or EXEC. Parameters let the same procedure work with different values.

Ways of passing parameters (MySQL syntax):

  • IN: the caller passes a value into the procedure (the default). The procedure cannot change the caller's variable.
  • OUT: the procedure sends a value back to the caller through the variable.
  • INOUT: the caller passes a value in, and the procedure may modify it and return it.

Parameters are passed by position, for example CALL p(10, @x). Some systems (SQL Server) also allow passing by name.

Example

DELIMITER //
CREATE PROCEDURE GetStudentCount(IN dept INT, OUT total INT)
BEGIN
  SELECT COUNT(*) INTO total
  FROM Student
  WHERE DeptID = dept;
END //
DELIMITER ;

CALL GetStudentCount(2, @cnt);
SELECT @cnt;

Here dept is an IN parameter that carries the input value 2, and total is an OUT parameter whose value is read back through the session variable @cnt. An INOUT example is CREATE PROCEDURE Double(INOUT n INT) SET n = n * 2;.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 5 marks

How timestamp based algorithm uses timestamp to serialize the execution of concurrent transactions? Explain in detail.

Answer

Timestamp-based concurrency control. Each transaction TT gets a unique timestamp TS(T)TS(T) when it starts (system clock or counter), so older transactions have smaller timestamps. The protocol makes the execution equivalent to the serial order of the timestamps, without using locks, so there are no deadlocks.

Each data item QQ keeps two values:

  • R-TS(Q)R\text{-}TS(Q): the largest timestamp of any transaction that successfully read QQ.
  • W-TS(Q)W\text{-}TS(Q): the largest timestamp of any transaction that successfully wrote QQ.

Rules

Read(Q) by TiT_i:

  • If TS(Ti)<W-TS(Q)TS(T_i) < W\text{-}TS(Q), TiT_i would read a value already overwritten by a younger transaction, so the read is rejected and TiT_i is rolled back and restarted with a new timestamp.
  • Otherwise the read is executed, and R-TS(Q)=max⁡(R-TS(Q),TS(Ti))R\text{-}TS(Q) = \max(R\text{-}TS(Q), TS(T_i)).

Write(Q) by TiT_i:

  • If TS(Ti)<R-TS(Q)TS(T_i) < R\text{-}TS(Q), a younger transaction has already read the old value, so the write is rejected and TiT_i is rolled back.
  • If TS(Ti)<W-TS(Q)TS(T_i) < W\text{-}TS(Q), the write is obsolete, so TiT_i is rolled back. (Thomas' write rule instead ignores such a write.)
  • Otherwise the write is executed and W-TS(Q)=TS(Ti)W\text{-}TS(Q) = TS(T_i).

Example. Let TS(T1)=5TS(T_1)=5 and TS(T2)=10TS(T_2)=10, with W-TS(Q)=0W\text{-}TS(Q)=0. If T2T_2 writes QQ, then W-TS(Q)=10W\text{-}TS(Q)=10. If T1T_1 now tries to read QQ, 5<105 < 10, so T1T_1 is aborted and restarted.

All conflicting operations are thus ordered by timestamp, which guarantees conflict serializability. The disadvantages are possible starvation by repeated restarts and cascading rollbacks (unless strict timestamping is used).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 5 marks

What are different types of indexing used in database? How index can be created using SQL? Write with example.

Answer

Indexing. An index is a data structure that speeds up searching for records, like the index of a book. It stores search-key values with pointers to the records.

Types of indexing

  1. Primary index: built on the ordered primary key of a sorted data file. It is usually sparse, with one entry per block.
  2. Clustering index: built on a non-key ordering field, where records with the same value are stored together.
  3. Secondary index: built on a non-ordering field (candidate or non-key). It is dense and has an entry for every record or value.
  4. Dense index: an index entry for every search-key value. Sparse index: entries for only some values (one per block).
  5. Multilevel index: an index on the index, to reduce search steps.
  6. B-tree / B+-tree index: balanced tree structures that give efficient search, insertion, deletion and range queries. They are the most widely used.
  7. Hash index: uses a hash function on the key, which is good for equality searches.
  8. Bitmap index: bit vectors for columns with few distinct values.

Creating an index in SQL

CREATE INDEX idx_student_name ON Student(Name);

CREATE UNIQUE INDEX idx_student_email ON Student(Email);

CREATE INDEX idx_dept_level ON Student(DeptID, Level);   -- composite index

DROP INDEX idx_student_name ON Student;

Queries such as SELECT * FROM Student WHERE Name = 'Ram'; can then use idx_student_name instead of scanning the whole table. The trade-off is extra storage and slower inserts and updates.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 10 marks

What are the advantages of normalization? Explain 3NF and BCNF with example.

Answer

Advantages of normalization

Normalization is the process of organising relations to reduce redundancy and avoid anomalies. Its advantages are:

  • Less redundancy: each fact is stored once, so storage is saved.
  • No update, insertion or deletion anomalies: a change is made in one place only.
  • Better data integrity and consistency: dependencies are enforced through keys.
  • Smaller, well-structured tables: easier to maintain, index and query specific data.
  • Flexible design: new data or attributes can be added with little effect on existing tables.

Third Normal Form (3NF)

A relation is in 3NF if it is in 2NF and no non-prime attribute is transitively dependent on the primary key. Equivalently, for every non-trivial FD X→AX \to A, either XX is a superkey or AA is a prime attribute.

Example: STUDENT(SID, Name, DeptID, DeptName) with SID→DeptIDSID \to DeptID and DeptID→DeptNameDeptID \to DeptName. Here SID→DeptNameSID \to DeptName is transitive, so the relation is not in 3NF. Decompose into:

  • STUDENT(SID, Name, DeptID)
  • DEPARTMENT(DeptID, DeptName)

Both are now in 3NF.

Boyce-Codd Normal Form (BCNF)

A relation is in BCNF if for every non-trivial FD X→YX \to Y, XX is a superkey. It is stricter than 3NF: 3NF allows X→AX \to A when AA is prime, BCNF does not.

Example: COURSE_TEACH(Student, Course, Teacher) with FDs (Student,Course)→Teacher(Student, Course) \to Teacher and Teacher→CourseTeacher \to Course (each teacher teaches one course). Candidate keys are (Student,Course)(Student, Course) and (Student,Teacher)(Student, Teacher). The relation is in 3NF because CourseCourse is prime, but Teacher→CourseTeacher \to Course violates BCNF as TeacherTeacher is not a superkey. Decompose into:

  • TEACHES(Teacher, Course)
  • ENROLS(Student, Teacher)

Now every determinant is a key, so both relations are in BCNF.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 10 marks

How ER model can be mapped to the relational data model? Explain with a proper example.

Answer

Mapping an ER model to the relational model

An ER schema is converted to relations using the following steps.

  1. Strong entity sets: each becomes a relation with its simple attributes; composite attributes are flattened into their components; the key attribute becomes the primary key.
  2. Weak entity sets: become a relation containing its own attributes plus the primary key of the owner entity as a foreign key. The primary key is (owner key + partial key).
  3. Multivalued attributes: become a separate relation holding the entity's key and the attribute value; the key of the new relation is the combination of both.
  4. 1:1 relationship: put the primary key of one side as a foreign key in the other (preferably the side with total participation).
  5. 1:N relationship: put the primary key of the "1" side as a foreign key in the "N" side relation.
  6. M:N relationship: create a new relation with the primary keys of both entities as foreign keys; their combination is the primary key. Relationship attributes are added to it.
  7. Higher-degree relationships: a new relation containing the keys of all participating entities.
  8. Specialization/generalization: either one relation per entity (subclass has superclass key), or a single relation with a type attribute.

Example

ER schema: STUDENT(SID, Name, {Phone}), DEPARTMENT(DID, DName), COURSE(CID, Title), relationships BELONGS_TO (DEPARTMENT 1 : N STUDENT) and ENROLLS (STUDENT M : N COURSE, attribute Grade).

Relational schema:

  • DEPARTMENT(DID, DName)
  • STUDENT(SID, Name, DID) where DID is a foreign key to DEPARTMENT (1:N mapping)
  • STUDENT_PHONE(SID, Phone) where SID is a foreign key (multivalued attribute)
  • COURSE(CID, Title)
  • ENROLLS(SID, CID, Grade) with primary key (SID,CID)(SID, CID) and both as foreign keys (M:N mapping)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2025 · 10 marks

a) What is inner join? Perform inner join to find the customer names who are going on flight to 'South Wales':
Customer (Cid, Name, Address, Age, Email)
Booking(Cid(FK), FlightID(FK), BookedDate)
Flight(FlightID, AirplaneCode, DepartureTime, Destination, Duration)
b) What are unary and ternary relationship? Write with examples.

Answer

(a) An inner join combines rows from two tables only where the join condition is satisfied; rows with no match in the other table are excluded.

To find customers booked on a flight to 'South Wales', join Customer, Booking and Flight:

SELECT DISTINCT c.Name
FROM Customer c
INNER JOIN Booking b ON c.Cid = b.Cid
INNER JOIN Flight f ON b.FlightID = f.FlightID
WHERE f.Destination = 'South Wales';

(b)

Unary (recursive) relationship: a relationship in which an entity set participates more than once, in different roles, so the degree is 1. Example: EMPLOYEE supervises EMPLOYEE; one employee acts as a supervisor and others as subordinates. Another example is a person being married to a person.

Ternary relationship: a relationship among three entity sets, so the degree is 3. Example: SUPPLY relating SUPPLIER, PROJECT and PART: a supplier supplies a part to a project. It cannot in general be replaced by three binary relationships without losing information. Another example: DOCTOR prescribes MEDICINE to PATIENT.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2026 · 1+4 marks

Define transaction. Describe ACID properties with example.

Answer

A transaction is a logical unit of database work consisting of one or more operations (reads and writes) that must be executed as a whole, taking the database from one consistent state to another. Example: transferring Rs 500 from account A to account B.

ACID properties

  1. Atomicity: all operations of a transaction are performed or none are ("all or nothing"). If the system fails after debiting A but before crediting B, the debit is rolled back.
  2. Consistency: a transaction takes the database from one valid state to another, preserving integrity constraints. In the transfer, the sum A+BA + B is the same before and after.
  3. Isolation: concurrent transactions behave as if executed serially; intermediate results of one are invisible to others. Another transaction reading A and B mid-transfer must not see the inconsistent total.
  4. Durability: once a transaction commits, its changes persist even after a crash, ensured by logs and recovery.

Example: T: read(A); A = A - 500; write(A); read(B); B = B + 500; write(B); commit. If A = 2000, B = 1000, after commit A = 1500 and B = 1500, the total stays 3000 (consistency), and the change survives a failure (durability).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2026 · 2.5+2.5 marks

Explain physical data independence and logical data independence.

Answer

Physical data independence is the ability to change the physical (internal) schema without changing the conceptual (logical) schema or application programs. Changes such as moving files to another disk, changing file organisation, adding or removing an index, or changing storage structures affect only the internal-to-conceptual mapping. Example: adding an index on Student(Name) speeds up queries but no application needs rewriting. It is relatively easy to achieve.

Logical data independence is the ability to change the conceptual schema without changing external schemas (user views) or application programs. Changes such as adding a new attribute or entity, or splitting or merging tables, are absorbed by modifying the external-to-conceptual mapping. Example: adding an Email column to Student does not disturb programs that do not use it. It is harder to achieve because applications depend closely on the logical structure.

Both are provided by the three-schema architecture (external, conceptual, internal).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2026 · 1+4 marks

What is stored procedure? Describe statement level trigger and multi row enabled trigger?

Answer

A stored procedure is a named, precompiled block of SQL and procedural statements stored in the database and executed on demand with a call. It can take parameters, reduces network traffic, improves reuse, performance and security.

CREATE PROCEDURE raise_salary(p_id NUMBER, p_pct NUMBER) AS
BEGIN
  UPDATE employee SET salary = salary * (1 + p_pct/100) WHERE eid = p_id;
END;

A trigger is a stored program that executes automatically when an INSERT, UPDATE or DELETE event occurs on a table.

Statement-level trigger: fires once per triggering SQL statement, regardless of how many rows are affected (even zero). It is the default when FOR EACH ROW is omitted. Used for auditing or restrictions on the operation as a whole.

CREATE TRIGGER trg_stmt
BEFORE DELETE ON student
BEGIN
  INSERT INTO audit_log VALUES ('DELETE on student', SYSDATE);
END;

Row-level (multi-row enabled) trigger: fires once for each row affected by the statement, so a statement that updates 100 rows fires it 100 times. It uses FOR EACH ROW and can access old and new values through :OLD and :NEW.

CREATE TRIGGER trg_row
AFTER UPDATE OF salary ON employee
FOR EACH ROW
BEGIN
  INSERT INTO sal_audit VALUES (:OLD.eid, :OLD.salary, :NEW.salary);
END;

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2026 · 2+3 marks

Define schedule and serializability with example. How can you test the serializability?

Answer

A schedule is a chronological ordering of the operations (read, write, commit, abort) of a set of concurrent transactions, preserving the order of operations within each transaction. A serial schedule runs transactions one after another with no interleaving; a non-serial schedule interleaves them.

A schedule is serializable if its effect is equivalent to that of some serial schedule of the same transactions. Serializability guarantees correctness of concurrent execution.

Example: with T1T_1: R(A), W(A) and T2T_2: R(B), W(B), the interleaving R1(A), R2(B), W1(A), W2(B) is serializable because the transactions touch different items and it equals T1T_1 then T2T_2. If both accessed A with conflicting writes in a cyclic order, it would not be.

Testing conflict serializability (precedence graph)

  1. Create a node for each transaction TiT_i.
  2. Add a directed edge Ti→TjT_i \to T_j if an operation of TiT_i conflicts with and precedes an operation of TjT_j on the same item. Conflicts: R-W, W-R, W-W by different transactions.
  3. If the graph has no cycle, the schedule is conflict serializable, and a topological order of the graph gives an equivalent serial schedule. If there is a cycle, it is not conflict serializable.

Example: W1(A), R2(A), W2(B), R1(B) gives edges T1→T2T_1 \to T_2 (on A) and T2→T1T_2 \to T_1 (on B), a cycle, so not serializable.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2026 · 1+4 marks

What is data model? What are its types?

Answer

A data model is a collection of conceptual tools for describing the data, data relationships, data semantics and consistency constraints of a database. It defines how data is structured and manipulated.

Types of data models

  1. Hierarchical model: data is organised as a tree of parent-child records (one parent per child), e.g. IMS.
  2. Network model: records are connected as a graph, allowing many-to-many links through sets and pointers, e.g. CODASYL.
  3. Relational model: data is stored in tables (relations) of rows and columns related through keys; based on set theory and queried with SQL, e.g. MySQL, Oracle.
  4. Entity-Relationship (ER) model: high-level conceptual model describing entities, attributes and relationships, drawn as ER diagrams.
  5. Object-oriented model: data is stored as objects with attributes and methods, supporting classes and inheritance.
  6. Object-relational model: relational model extended with object features such as user-defined types.
  7. Semi-structured / document model: e.g. XML and JSON (MongoDB), for flexible schemas.

By abstraction level they are also grouped as conceptual (high-level), representational/logical (relational, network, hierarchical) and physical (low-level) models.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2026 · 1+4 marks

Define query processing and steps in query processing.

Answer

Query processing is the set of activities by which a high-level query (such as SQL) is translated into low-level operations, optimised and executed to extract the requested data from the database.

Steps

  1. Parsing and translation: the query is checked for syntax, and relation and attribute names are validated against the catalog. It is translated into an internal form, usually a relational algebra expression or query tree.
  2. Optimization: the optimizer generates alternative equivalent expressions and evaluation plans (join order, access paths, use of indexes, algorithms such as nested-loop or hash join), estimates cost using statistics (disk I/O, CPU), and chooses the cheapest plan.
  3. Evaluation (execution): the query execution engine runs the chosen plan, retrieves the data through the storage manager and returns the output.

Example: SELECT Name FROM Student WHERE Roll = 5 can be written as πName(σRoll=5(Student))\pi_{Name}(\sigma_{Roll=5}(Student)), and the optimizer may choose an index scan on Roll instead of a full table scan.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2026 · 3+7 marks

Describe DDL and DML queries with example. Explain database system architecture.

Answer

DDL and DML

DDL (Data Definition Language) defines and modifies the structure (schema) of database objects. Its commands are auto-committed. Main commands: CREATE, ALTER, DROP, TRUNCATE, RENAME.

CREATE TABLE student (sid INT PRIMARY KEY, name VARCHAR(30), age INT);
ALTER TABLE student ADD email VARCHAR(40);
DROP TABLE student;

DML (Data Manipulation Language) manipulates the data stored in the tables. Main commands: SELECT, INSERT, UPDATE, DELETE.

INSERT INTO student VALUES (1, 'Ram', 20, 'ram@x.com');
UPDATE student SET age = 21 WHERE sid = 1;
DELETE FROM student WHERE sid = 1;
SELECT name FROM student WHERE age > 18;

Database system architecture

The architecture describes the components of a DBMS and how users interact with it.

Three-schema (ANSI-SPARC) architecture

  • External level (view level): user-specific views of the data.
  • Conceptual level: the logical structure of the whole database (entities, relationships, constraints).
  • Internal level (physical): how data is stored (files, indexes, access paths).

Mappings between the levels give logical and physical data independence.

Components of a DBMS

  • Query processor: DDL interpreter, DML compiler (query optimizer) and query evaluation engine.
  • Storage manager: authorization and integrity manager, transaction manager, file manager and buffer manager, handling files, indices and the data dictionary.
  • Disk storage: data files, data dictionary (metadata) and indices.

Application architectures

  • Two-tier: client applications communicate directly with the database server (e.g. via ODBC/JDBC).
  • Three-tier: client (presentation) → application server (business logic) → database server. This suits web applications, with better scalability and security.

Users include naive users, application programmers, sophisticated users and the DBA.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2026 · 2+2+6 marks

What is normalization? What are its advantages? Describe its types with appropriate examples.

Answer

Normalization is a systematic process of decomposing relations into smaller, well-structured relations using functional dependencies and keys, in order to eliminate redundancy and insertion, update and deletion anomalies while preserving data and dependencies.

Advantages

  • Reduces data redundancy and saves storage.
  • Eliminates insert, update and delete anomalies.
  • Improves data consistency and integrity.
  • Gives a logical, easily maintainable database design.

Normal forms

1NF: all attributes are atomic (single-valued, no repeating groups). Example: STUDENT(SID, Name, Phones) with Phones = "98, 97" violates 1NF. Fix: one phone per row, STUDENT_PHONE(SID, Phone).

2NF: in 1NF and no partial dependency of a non-prime attribute on part of a composite key. Example: ENROL(SID, CID, Grade, CourseName) with key (SID,CID)(SID, CID) and CID→CourseNameCID \to CourseName is a partial dependency. Decompose into ENROL(SID, CID, Grade) and COURSE(CID, CourseName).

3NF: in 2NF and no transitive dependency of non-prime attributes on the key. Example: EMP(EID, Name, DeptID, DeptName) with EID→DeptID→DeptNameEID \to DeptID \to DeptName. Decompose into EMP(EID, Name, DeptID) and DEPT(DeptID, DeptName).

BCNF: for every non-trivial FD X→YX \to Y, XX is a superkey. Example: R(Student, Course, Teacher) with Teacher→CourseTeacher \to Course. Decompose into (Teacher, Course) and (Student, Teacher).

4NF: in BCNF and no non-trivial multivalued dependency other than on a superkey. Example: R(Employee, Skill, Language) where skills and languages are independent is split into (Employee, Skill) and (Employee, Language).

5NF: no join dependency that is not implied by candidate keys; the relation cannot be further decomposed losslessly into smaller relations.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2026 · 3+2+2+1+2 marks

Consider the following schema:
Guest (Gid, Gname, Age, Gender)
STAFF (Sid, Sname, Age, Gender, Roles)
SERVICE (serId, serName, Price)
ASSISTS (Gid, Sid) (Which staff assists which guest) PROVIDES (serId, Sid) (Which staff provides which service)
Write SQL Queries:
a. Find name of guests who are VIP.
b. Find total number of guests assisted by staff Ram.
c. Find name of staff whose name starts with A and ends with A.
d. Display name of staff who provides laundry service.
e. Give 10% discount to female guests on the price of service they receive.

Answer

The schema does not contain a VIP column in Guest, so we assume a Guest attribute Type (or Category) holds the value 'VIP'. Likewise, assume Roles/serName contain 'Laundry' and Price is the service price. Queries:

(a) Names of VIP guests:

SELECT Gname FROM Guest WHERE Type = 'VIP';

(b) Total number of guests assisted by staff Ram:

SELECT COUNT(DISTINCT a.Gid)
FROM ASSISTS a JOIN STAFF s ON a.Sid = s.Sid
WHERE s.Sname = 'Ram';

(c) Staff whose name starts with A and ends with A:

SELECT Sname FROM STAFF WHERE Sname LIKE 'A%A';

(Use UPPER(Sname) LIKE 'A%A' for case-insensitivity.)

(d) Staff who provide the laundry service:

SELECT s.Sname
FROM STAFF s
JOIN PROVIDES p ON s.Sid = p.Sid
JOIN SERVICE sv ON p.serId = sv.serId
WHERE sv.serName = 'Laundry';

(e) 10% discount on the price of services received by female guests. A guest receives the services provided by the staff who assist them, so the price of those services is reduced:

UPDATE SERVICE
SET Price = Price * 0.90
WHERE serId IN (
  SELECT p.serId
  FROM PROVIDES p
  JOIN ASSISTS a ON p.Sid = a.Sid
  JOIN Guest g ON a.Gid = g.Gid
  WHERE g.Gender = 'F'
);

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

Questions from TU BCA 2020 Fourth Semester Operating System (TU board exam, 2020), TU BCA 2021 Fourth Semester Operating System (TU board exam, 2021), TU BCA 2022 Fourth Semester Operating System (TU board exam, 2022), TU BCA 2023 Fourth Semester Operating System (TU board exam, 2023), TU BCA 2024 Fourth Semester Operating System (TU board exam, 2024), TU BCA 2025 Fourth Semester Operating System (TU board exam, 2025), TU BCA 2026 Fourth Semester Operating System (TU board exam, 2026), TU BCA 2020 Fourth Semester Database Management System (TU board exam, 2020), TU BCA 2021 Fourth Semester Database Management System (TU board exam, 2021), TU BCA 2022 Fourth Semester Database Management System (TU board exam, 2022), TU BCA 2023 Fourth Semester Database Management System (TU board exam, 2023), TU BCA 2024 Fourth Semester Database Management System (TU board exam, 2024), TU BCA 2025 Fourth Semester Database Management System (TU board exam, 2025), TU BCA 2026 Fourth Semester Database Management System (TU board exam, 2026), TU BCA 2020 Fourth Semester Software Engineering (TU board exam, 2020), TU BCA 2021 Fourth Semester Software Engineering (TU board exam, 2021), TU BCA 2022 Fourth Semester Software Engineering (TU board exam, 2022), TU BCA 2023 Fourth Semester Software Engineering (TU board exam, 2023), TU BCA 2024 Fourth Semester Software Engineering (TU board exam, 2024), TU BCA 2025 Fourth Semester Software Engineering (TU board exam, 2025), TU BCA 2026 Fourth Semester Software Engineering (TU board exam, 2026), TU BCA 2020 Fourth Semester Numerical Method (TU board exam, 2020), TU BCA 2021 Fourth Semester Numerical Method (TU board exam, 2021), TU BCA 2022 Fourth Semester Numerical Method (TU board exam, 2022), TU BCA 2023 Fourth Semester Numerical Method (TU board exam, 2023), TU BCA 2024 Fourth Semester Numerical Method (TU board exam, 2024), TU BCA 2025 Fourth Semester Numerical Method (TU board exam, 2025), TU BCA 2026 Fourth Semester Numerical Method (TU board exam, 2026), TU BCA 2019 Fourth Semester Scripting Language (TU board exam, 2019), TU BCA 2020 Fourth Semester Scripting Language (TU board exam, 2020), TU BCA 2021 Fourth Semester Scripting Language (TU board exam, 2021), TU BCA 2022 Fourth Semester Scripting Language (TU board exam, 2022), TU BCA 2023 Fourth Semester Scripting Language (TU board exam, 2023), TU BCA 2024 Fourth Semester Scripting Language (TU board exam, 2024), TU BCA 2025 Fourth Semester Scripting Language (TU board exam, 2025) and TU BCA 2026 Fourth Semester Scripting Language (TU board exam, 2026). Answers are written for this site; check them against your class notes.