49.0 KB · commit 40bb182
| year | 2021 |
|---|---|
| exam | B.Sc. Engineering 2nd Year Even Semester Examination, 2021 |
| course_code | ECE 2215 |
| course_title | Database Systems |
| full_marks | 72 |
| time | 3 Hours |
| layer | exam-style |
← Prev: 2020 | Explanation Layer | Original Question Paper | Next: 2023 →
Topic: T01.2 · File system vs DBMS · Section A · CLO1 (Repeated question: Also asked in 2017 | Solved in T01)
Question. Discuss four significant differences between a file-processing system and a DBMS.
Answer.
| Feature | File Processing System | DBMS (Database Management System) |
|---|---|---|
| Data Redundancy & Inconsistency | Data is duplicated across multiple separate files. Different copies easily get out of sync. | Centralizes data storage. Normalization avoids duplication and keeps copies consistent. |
| Data Access & Retrieval | Programmers must write a new custom program in C or Java for each new query. | Users write declarative queries (like SQL) to retrieve ad-hoc data quickly without new code. |
| Data Isolation & Independence | Data structures and application code are tightly coupled. Changing a file structure breaks programs. | Provides data abstraction. Changes to physical storage structures do not affect application programs. |
| Concurrent Access & Recovery | Hard to coordinate simultaneous access. Multiple updates cause lost data. Crash recovery is manual. | Built-in concurrency control prevents conflicting updates. Automated logging and recovery preserve ACID properties. |
Variant for 2021 Q.1(a) (4 marks): The same four differences directly answer the question.
Topic: T01.3 · Functions of the DBA and relation schema · Section A · CLO1 (Repeated question: Also asked in 2020 | Solved in T01)
Question. What are the five main functions of a database administrator?
Answer.
Five Main Functions of a Database Administrator (DBA):
Relation Schema:
A relation schema is the formal logical definition or blueprint of a relation (table). It specifies the name of the relation along with its set of attributes (columns) and their corresponding domains (data types).
Variant for 2021 Q.1(b) (3 marks): State and explain the five DBA functions above; omit the relation schema.
Variant for 2017 Q.1(c) (2 marks): List only the names: (1) Schema definition, (2) Storage structure and access-method definition, (3) Schema and physical-organization modification, (4) Granting of authorization for data access, (5) Routine maintenance.
Topic: T03.3 · Referential integrity & FK syntax (MySQL) · Section A · CLO2
Question. How do we achieve referential integrity in DBMS? Provide necessary MySQL query with an appropriate example.
Answer.
1. How Referential Integrity is Achieved in DBMS:
Referential integrity ensures that relationships between tables remain consistent. It requires that any foreign key value in a referencing table must exist as a primary key value in the referenced table, or be NULL.
A DBMS achieves referential integrity through three mechanisms:
FOREIGN KEY ... REFERENCES clause.INSERT, UPDATE, and DELETE commands. It blocks any operation that creates orphan child records.CASCADE: Deleting or updating a parent row automatically deletes or updates matching child rows.SET NULL: Sets child foreign key columns to NULL when the parent row is deleted or updated.RESTRICT / NO ACTION: Default rule; rejects parent deletion or update if matching child rows exist.2. MySQL DDL Query Example:
-- Parent table (Referenced relation)
CREATE TABLE Department (
dept_name VARCHAR(20) PRIMARY KEY,
building VARCHAR(20),
budget DECIMAL(12, 2)
);
-- Child table (Referencing relation)
CREATE TABLE Student (
student_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
dept_name VARCHAR(20),
FOREIGN KEY (dept_name) REFERENCES Department(dept_name)
ON DELETE CASCADE
ON UPDATE CASCADE
);
3. Operation and Violation Demonstration:
Populate a valid parent department:
INSERT INTO Department VALUES ('ECE', 'Academic Building 2', 500000.00);
INSERT INTO Student VALUES (101, 'Akib', 'ECE'); -- Allowed
Now attempt a violating insert with a nonexistent department:
INSERT INTO Student VALUES (102, 'Shuvo', 'ME');
MySQL System Response:
MySQL rejects the insert and raises an integrity violation error:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`university`.`Student`, CONSTRAINT `student_ibfk_1` FOREIGN KEY (`dept_name`) REFERENCES `Department` (`dept_name`) ON DELETE CASCADE ON UPDATE CASCADE)
If 'ECE' is deleted from Department, ON DELETE CASCADE automatically deletes student 101. This keeps the database consistent.
Topic: T04.2 · Write RA queries on a given schema · Section A · CLO2
Question.
Consider the following relation schema:
customer (id, name, age, gender)
order (id, product, price, date)
Now, give expression in relational algebra to-
(i) find name of the customers who are male.
(ii) find name of all customers who have purchased car as product.
(iii) find the details of all customers who have purchased "phone" as product and the price is less than $300.
Answer.
Assumption: The attribute order.id represents the customer identifier that placed the order.
(i) Names of male customers:
Πname(σgender="male"(customer))(ii) Names of all customers who purchased car as product:
Join customer and order on id, filter for product "car", and project customer names:
(iii) Details of all customers who purchased "phone" priced under $300:
Filter order records for product "phone" with price below 300, then join with customer:
Ttarget_orders←σproduct="phone"∧price<300(order) customer⋈Ttarget_ordersTo project customer attributes only:
Πcustomer.id,name,age,gender(customer⋈Ttarget_orders)Topic: T03.2 · Keys: super / candidate / primary / alternate / composite / foreign · Section A · CLO1 (Repeated question: Also asked in 2023 | Solved in T03)
Question. Differentiate among Superkey, Candidate Key and Primary Key with an appropriate example.
Answer.
A key is an attribute or set of attributes used to identify rows in a table.
Distinctions Among Keys:
| Key Type | Definition | Minimality | NULL Allowed |
|---|---|---|---|
| (i) Primary Key | The candidate key chosen by the database designer to identify tuples uniquely. | Yes (minimal) | No (never allowed) |
| (ii) Candidate Key | A minimal super key. Removing any attribute destroys uniqueness. | Yes (strictly minimal) | Yes (unless constrained NOT NULL) |
| (iii) Super Key | Any set of attributes that uniquely identifies a row. May contain extra attributes. | No (can have redundant attributes) | No for identifying columns |
| (iv) Composite Key | A key that consists of two or more attributes rather than a single attribute. | Can be minimal (candidate) or non-minimal | Depends on whether it is PK or unique |
Relationship:
Primary Key⊆Candidate Keys⊆Super KeysRunning Example:
Consider relation Student(student_id,name,email,nid,dept_name):
| student_id | name | nid | dept_name | |
|---|---|---|---|---|
| 101 | Akib | akib@gmail.com | 1999123456 | ECE |
| 102 | Shuvo | shuvo@gmail.com | 2000654321 | ECE |
| 103 | Sakib | sakib@gmail.com | 2001987654 | ETE |
Short version for 2018 Q.2(a) (4 marks): Omit (iv) Composite key. Keep the definitions, distinctions table, and the Student running example for Super Key, Candidate Key, and Primary Key.
Short version for 2021 Q.2(b) (3 marks): Same as 2018 Q.2(a). Present the 3-row distinction table and the Student relation key classification.
Topic: T04.3 · Explain an RA expression in words · Section A · CLO2
Question.
For each expression, explain in words what the expression does.
Where takes(id, course, sec_id, sem, year, grade)
(i) σyear≥2009(takes)⋈student
(ii) Πid,name,course_id(student⋈takes)
Answer.
(i) Expression: σyear≥2009(takes)⋈student
takes relation to keep only enrollment records where year is 2009 or later.student relation on their common attribute id.(ii) Expression: Πid,name,course_id(student⋈takes)
student and takes on id.id), name (name), and course ID (course_id). Discards other attributes and eliminates duplicates.Topic: T05.2 · DDL + DML warm-up: CREATE, INSERT, ALTER ... ADD, UPDATE, DELETE, rename, filter · Section A · CLO2
Question.
Consider the following E-comerce database:
client (c_no, name, city, state, baldue)
product (p_no, description, profit_percent, quantity, sell_price, cost_price)
salesman (s_no, name, city, state, sal_amount, target, sold_yearly, remarks)
Now write the appropriate MySql code to execute the following query:
(i) Change the city of client no "C0005" to "Barishal".
(ii) Delete all salesmen whose salaries are equal to 35000 Tk.
(iii) Add a column called "Telephone" of datatype numeric and size = '11' to the client table.
(iv) Find products whose selling price is more than 500. Calculate a new selling price as original price15. Rename the new column in the output as new_price.
(Note: "E-comerce" and "MySql" printed verbatim from original question paper)*
Answer.
(i) Change city of client "C0005" to "Barishal":
UPDATE client
SET city = 'Barishal'
WHERE c_no = 'C0005';
(ii) Delete salesmen whose salary is 35000 Tk:
DELETE FROM salesman
WHERE sal_amount = 35000;
(iii) Add column "Telephone" of numeric type and size 11 to client table:
ALTER TABLE client
ADD Telephone NUMERIC(11);
(iv) Find products with sell_price > 500 and calculate new selling price:
SELECT p_no,
description,
sell_price,
sell_price * 15 AS new_price
FROM product
WHERE sell_price > 500;
Topic: T02.2 · Attribute types · Section A · CLO4
Question.
Define entity and attribute. Explain the following attributes-
(i) Multi-valued
(ii) Derived
(iii) Composite
Answer.
ID = 22222, or a student).name, salary).Explanation of Attribute Types:
Multi-valued Attribute:
phone_numbers = {0171..., 0181...}).Derived Attribute:
age derived from current date minus date_of_birth.Composite Attribute:
name divided into first_name, middle_initial, and last_name.
Figure: Complex Attributes in ER Diagram Notation (Deck 05, Slide 19)
Topic: T05.7 · Multi-table business-schema query sets (MySQL): Covid, Company, Insurance, E-commerce · Section A · CLO2
Question.
Consider the following E-comerce database:
client (c_no, name, city, state, Baldue)
product (p_no, description, profit_percent, quantity, sell_price, cost_price)
salesman (s_no, name, city, state, sal_amount, target, sold_yearly, remarks)
order (order_no, client_no, order_date, delivery_address, salesman_no, del_type, del_date, order_status)
order_details (order_no, product_no, quantity_ordered, product_rate)
(i) Find the total value of each product sold.
(ii) Find the products and their quantities for the orders placed by client no "C0001" and "C0002".
(iii) Find the product no and description of the products not being sold.
(iv) Find if the product "Lyera Top" has been ordered by any client and print the client_no, name to whom it was sold.
(Note: "E-comerce" and "Lyera Top" printed verbatim from original question paper)
Answer.
(i) Total value of each product sold:
SELECT od.product_no,
p.description,
SUM(od.quantity_ordered * od.product_rate) AS total_value
FROM order_details od
JOIN product p ON od.product_no = p.p_no
GROUP BY od.product_no, p.description;
(ii) Products and quantities ordered by client "C0001" and "C0002":
SELECT o.client_no,
od.product_no,
p.description,
od.quantity_ordered
FROM `order` o
JOIN order_details od ON o.order_no = od.order_no
JOIN product p ON od.product_no = p.p_no
WHERE o.client_no IN ('C0001', 'C0002');
(iii) Product number and description of products not sold:
SELECT p_no, description
FROM product
WHERE p_no NOT IN (
SELECT DISTINCT product_no
FROM order_details
);
(Alternative using NOT EXISTS:
SELECT p.p_no, p.description
FROM product p
WHERE NOT EXISTS (
SELECT 1
FROM order_details od
WHERE od.product_no = p.p_no
);
)
(iv) Check if "Lyera Top" was ordered and display client number and name:
SELECT DISTINCT c.c_no, c.name
FROM client c
JOIN `order` o ON c.c_no = o.client_no
JOIN order_details od ON o.order_no = od.order_no
JOIN product p ON od.product_no = p.p_no
WHERE p.description = 'Lyera Top';
Topic: T02.1 · Entity sets, relationship sets, types of relationships · Section B · CLO1
Question. What is ER diagram? Illustrate different types of relationship that can be represented in ER diagram.
Answer.
An Entity-Relationship (E-R) diagram is a graphical tool used in database design. It represents the conceptual schema of an enterprise by depicting entities, their attributes, and the relationships among them.
The degree of a relationship set is the number of participating entity sets. Different types of relationships based on degree include:
Unary (Recursive) Relationship (Degree 1):
course entity related to another course entity via a prereq relationship (roles: course_id and prereq_id).Binary Relationship (Degree 2):
instructor and student linked by the advisor relationship.Ternary Relationship (Degree 3):
proj_guide linking instructor, student, and project.| Relationship Type | Degree | Description | Example |
|---|---|---|---|
| Unary (Recursive) | 1 | Association among entities of the same entity set | Course prereq Course |
| Binary | 2 | Association between two distinct entity sets | Instructor advisor Student |
| Ternary | 3 | Association among three distinct entity sets | Instructor, Student, Project proj_guide |
| n-ary | n | Association among n entity sets | Rare; usually decomposed into binary |
Topic: T08.4 · Attribute closure X+, F+, finding candidate keys · Section B · CLO1
Question.
Compute the closure of the following set F of functional dependencies for relational schema r (A, B, C, D, E).
A→BC
CD→E
B→D
E→A
List the candidate Keys for R.
Answer.
The complete closure F+ contains over one hundred trivial and non-trivial dependencies, which is too large to write out fully.
We compute the attribute closures of each single attribute and pair under F:
A+:
B+:
C+:
D+:
E+:
Key Two-Attribute Closures:
Key Non-Trivial Functional Dependencies in F+ (derived using Armstrong's Axioms):
A candidate key is a minimal set of attributes whose closure contains all attributes {A,B,C,D,E}.
Topic: T08.7 · 2NF test from an FD set · Section B · CLO1
Question.
Given a relation R (A, B, C, D) and functional dependency at FD = { AB → CD, B → C }. Determine whether the given R is in 2NF? If not, convert it into 2NF.
(Note: "functional dependency at FD" printed verbatim from original question paper)
Answer.
Given relation R(A,B,C,D) and functional dependencies:
FD={AB→CD,B→C}A relation is in 2NF if it is in 1NF and no non-prime attribute depends on a proper subset of any candidate key.
Examine the dependencies:
Because a partial dependency exists (B→C), the relation R is NOT in 2NF.
To achieve 2NF, we decompose R by isolating the partial dependency into its own relation:
Verification:
Topic: T08.5 · Canonical cover Fc (and how it differs from normalization) · Section B · CLO1
Question. Differentiate between normalization and canonical cover in DBMS.
Answer.
| Parameter | Normalization | Canonical Cover (Fc) |
|---|---|---|
| Definition | The process of decomposing relation schemas to eliminate redundancy and update/delete/insert anomalies. | A minimal, non-redundant set of functional dependencies equivalent to the original FD set (Fc≡F). |
| Primary Goal | Design high-integrity tables that eliminate anomalies and avoid data duplication. | Simplify the set of integrity constraints so DBMS updates can be validated with minimal overhead. |
| Input | A relation schema R and its functional dependencies F. | A set of functional dependencies F. |
| Output | A collection of decomposed relations {R1,R2,…,Rk} in a desired normal form (e.g., 3NF, BCNF). | A simplified functional dependency set Fc with no extraneous attributes and unique left-hand sides. |
| Level of Operation | Operates on the schema design level (splitting tables and foreign keys). | Operates purely on the mathematical dependency level (simplifying FDs). |
Topic: T08.5 · Canonical cover Fc (and how it differs from normalization) · Section B · CLO1
Question.
Define Functional dependency. Consider the following functional dependency set:
FD={
A→BC,
CD→E,
B→D,
E→A
}
Find the canonical form of the FD set.
Answer.
A functional dependency (FD) is a constraint between two sets of attributes in a relation schema R.
Let α⊆R and β⊆R. The functional dependency:
α→βholds on R if, in every legal relation instance r(R), whenever any two tuples t1 and t2 have the same values for attributes in α, they must also have the same values for attributes in β:
If t1[α]=t2[α]⟹t1[β]=t2[β]We say α functionally determines β.
A canonical cover Fc satisfies two conditions:
Step 1: Apply the Union Rule to combine identical LHS
In the given set F={A→BC,CD→E,B→D,E→A}, the left-hand sides are A,CD,B,E. All left-hand sides are already unique.
Step 2: Test for Extraneous Attributes
Check A→BC:
Check CD→E:
Check B→D:
Both LHS and RHS have a single attribute. Neither can be removed without dropping the dependency entirely.
Check E→A:
Both LHS and RHS have a single attribute. Neither can be removed.
Step 3: Resulting Canonical Cover
Since there are no extraneous attributes, the canonical cover is:
(Note: In minimal cover form with singleton right-hand sides, the equivalent set is {A→B,A→C,CD→E,B→D,E→A}. Both representations are correct.)
Topic: T08.1 · Why normalize: redundancy and insert/update/delete anomalies · Section B · CLO1
Question.
Consider the following table:
| st_id | Name | Course | Session | Fee | Dept |
|---|---|---|---|---|---|
| 101 | Devi | DBMS | 2022 | 90k | CS |
| 102 | Sona | DBMS | 2022 | 90k | CS |
| 103 | Varun | DBMS | 2022 | 90k | CS |
| 104 | Satish | DBMS | 2022 | 90k | CS |
| 105 | Amisha | DBMS | 2022 | 90k | CS |
Answer.
Yes, significant data redundancy exists.
The attributes Course ("DBMS"), Session ("2022"), Fee ("90k"), and Dept ("CS") are duplicated across all 5 rows. In this schema, Fee and Dept depend on Course, not on the primary key st_id. Storing course-level attributes in every student record creates column-level duplication.
st_id cannot be NULL due to the Entity Integrity constraint.Topic: T09.1 · ACID properties · Section B · CLO1 (Repeated question: Also asked in 2017 | Solved in T09)
Question. Explain the ACID properties of transaction.
Answer.
A transaction is a logical unit of program execution that accesses and updates data items. To preserve data integrity during crashes and concurrent access, the DBMS must ensure the four ACID properties:
Atomicity ("All-or-None"):
Consistency (Preservation of Invariants):
Isolation (Shielding Concurrent Access):
Durability (Persistence):
Short version for 2024 Q.6(c) (2 marks):
Topic: T10.3 · Precedence-graph test → cycle → serial order(s) · Section B · CLO3
Question.
Define conflict serializability. Check whether the following schedule is a conflict serializable or not.
| T1 | T2 |
|---|---|
| read(A) | |
| write(A) | |
| read(A) | |
| write(A) | |
| read(B) | |
| write(B) | |
| read(B) | |
| write(B) |
Answer.
A schedule S is conflict serializable if it is conflict equivalent to some serial schedule. Two schedules are conflict equivalent if one can be transformed into the other by swapping non-conflicting adjacent instructions.
The schedule contains two transactions, T1 and T2, accessing items A and B:
Every conflict directs from T1 to T2. There is no instruction in T2 executed before a conflicting instruction in T1.

The precedence graph has one directed edge: T1→T2. It contains no cycles.
Result: The schedule is conflict serializable. The equivalent serial execution order is:
⟨T1,T2⟩Topic: T10.3 · Precedence-graph test → cycle → serial order(s) · Section B · CLO3
Question.
Consider the following schedule:
| T1 | T2 |
|---|---|
| r(A) | |
| w(A) | |
| r(B) | |
| w(B) | |
| r(B) | |
| w(B) | |
| r(A) | |
| w(A) |
Answer.
We trace all conflicting operations between T1 and T2:

The graph contains two directed edges:
This forms a cycle:
T1⟷T2Result: Because the precedence graph contains a cycle, the schedule is NOT serializable. There is no equivalent order of execution.
Topic: T11.4 · Deadlock: conditions, prevention vs detection, wait-for graph, victim selection · Section B · CLO1
Question.
What is deadlock? Consider the following wait-for-graph:
Determine whether the schedule contains any deadlock or not.
(Refer to the Wait-for-Graph Diagram and Detailed Text Representation below)
Answer.
Deadlock:
A deadlock is a state where each transaction in a set is waiting for a resource or data lock held by another transaction in that set. None of the transactions can continue execution.
Analysis of the Wait-For Graph:
The given wait-for graph has:
A directed edge Ti→Tj means transaction Ti is waiting for transaction Tj to release a required lock.
Cycle Detection:
We trace the directed edges among transactions T2,T4, and T5:
This forms a closed directed cycle.
Verdict:
Yes, the schedule contains a deadlock.
Transactions in Deadlock:
Transactions T2,T4, and T5 are deadlocked. (Note: T1 is waiting on T2,T3,T4, but is not part of the cycle. T3 has no outgoing edges and is not blocked).
Breaking the Deadlock:
The DBMS must select one transaction in the cycle (T2,T4, or T5) as a victim based on minimum abort cost, roll it back, and release its locks. This breaks the cycle and allows the remaining transactions to complete.
Topic: T13.2 · SQL injection: how it works and prevention · Section B · CLO4
Question. What is SQL injection attack? Describe the precautions that should be taken to prevent this attack.
Answer.
1. What is an SQL Injection Attack?
An SQL injection attack occurs when an attacker inputs malicious SQL commands into an application input field. The application concatenates this untrusted input directly into a dynamic SQL query string. The database parser interprets the malicious input as SQL instructions rather than data. This allows the attacker to bypass authentication, read unauthorized data, or modify and delete tables.
2. How It Works
Consider an application that builds a query using string concatenation:
# Vulnerable query construction
query = "SELECT * FROM instructor WHERE name = '" + user_input + "'"
' OR '1'='1SELECT * FROM instructor WHERE name = '' OR '1'='1';
Mechanism: The quote closes the name literal. The '1'='1' condition is always true. The database returns all records in the instructor table.
Scenario 2: Destructive Attack (Piggybacked Query)
'; DROP TABLE student; -- SELECT * FROM instructor WHERE name = ''; DROP TABLE student; -- ';
DROP TABLE student statement. The trailing -- treats the remaining query syntax as a comment.3. Precautions to Prevent SQL Injection
Use Prepared Statements (Parameterized Queries): This is the primary defense. The application precompiles the SQL query structure with placeholders. User input is bound separately as data parameters. The parser never executes parameter content as SQL commands.
# Secure parameterized query
cursor.execute("SELECT * FROM instructor WHERE name = %s", (user_input,))
In Java/JDBC, use PreparedStatement with ? markers and setString().
Input Validation and Whitelisting: Validate data types, lengths, and patterns before passing them to queries. For dynamic query parts like table or column names that cannot use parameters, check input against an explicit whitelist of allowed identifiers.
Enforce Least Privilege:
Configure database user accounts with minimal necessary privileges. A public web application account should only have SELECT or INSERT access. It must never have administrative permissions like DROP TABLE or GRANT.
Use Parameterized Stored Procedures: Wrap database operations inside stored procedures with typed parameters. Do not concatenate dynamic SQL inside the stored procedure body.
Suppress Database Error Messages: Hide internal database error details, table names, and stack traces from end users. Display generic error pages instead.
Short version for 2020 Q.4(a) (4 marks): Provide the definition, the ' OR '1'='1 exploit example, and the three core precautions: prepared statements, input validation, and least privilege.
Topic: T02.4 · Weak vs strong entity sets · Section B · CLO1 (Repeated question: Also asked in 2018 | Solved in T02)
Question. Explain weak and strong entity set with appropriate example.
Answer.
Entity Set:
An entity set is a collection of entities of the same type that share the same properties or attributes (e.g., the set of all students in a university).
| Feature | Strong Entity Set | Weak Entity Set |
|---|---|---|
| Primary Key | Has sufficient attributes to form its own primary key. | Lacks a primary key of its own. Uses a partial key (discriminator). |
| Existence Dependency | Independent. Does not depend on another entity set. | Existence-dependent on an identifying (strong) entity set. |
| E-R Notation | Single rectangle. | Double rectangle. |
| Relationship Set | Connected via regular relationship (single diamond). | Connected via identifying relationship (double diamond). |
| Discriminator Key | None (uses full primary key underlined with solid line). | Has a discriminator underlined with a dashed line. |
| Composite PK | Its own primary key. | Formed by (Owner Primary Key + Discriminator). |
| Example | course with primary key course_id. | section with discriminator sec_id, semester, year. |
Figure: Expressing Weak Entity Sets in ER Diagram (Deck 05, Slide 37)
course has attributes course_id (PK), title, credits. It exists independently.section has attributes sec_id, semester, year. A section number like Sec 1 is meaningless without knowing the course. Its full primary key is (course_id, sec_id, semester, year).Short version for 2020 Q.2(c) and 2021 Q.8(c) (2 marks):
State the comparison table rows (Primary Key, Dependency, Notation, Example) and omit the separate entity set definition.
← Prev: 2020 | Explanation Layer | Original Question Paper | Next: 2023 →