74.0 KB · commit 40bb182
| year | 2019 |
|---|---|
| exam | B.Sc. Engineering 2nd Year Even Semester Examination, 2019 |
| course_code | ECE 2215 |
| course_title | Database Systems |
| full_marks | 72 |
| time | 3 Hours |
| layer | explanation |
← Prev: 2018 | Exam-Style Layer | Original Question Paper | Next: 2020 →
Topic: T01.2 · File system vs DBMS · Section A
Question. Why DBMS is important? What are its advantages?
Answer.
What the examiner wants.
A brief statement on why a DBMS is important (~1 mark) and a structured list of at least 4 to 5 key advantages over file systems (~2 marks).
Key idea.
A DBMS provides a central, reliable layer between applications and physical storage. Its advantages directly fix the classic drawbacks of file processing systems: duplicate data, lack of ad-hoc access, and crash vulnerability.
Step-by-step solution.
Importance of DBMS:
A DBMS provides centralized, secure, and coordinated control over an organization's data. It replaces scattered operating system files and ensures that data remains reliable, shared, and recoverable during hardware or software crashes.
Advantages of DBMS over File Processing Systems:
Variant for 2023 Q.1(b) (3 marks): Focus directly on the 5 advantages over file processing systems; omit the general importance statement.
Check.
Quick self-test:
Exam tip.
List 5 numbered advantages with bold titles. This guarantees full marks even if an examiner deducts for a brief point.
Sources.
Topic: T02.4 · Weak vs strong entity sets · Section A
Question. What are entity and entity set? How is a weak entity set handled in DBMS? Explain.
Answer.
What the examiner wants.
Definitions of entity and entity set (1 mark). Clear explanation of the technical steps a DBMS uses to implement a weak entity set in relational tables (2 marks).
Key idea.
Relational databases do not have a native "weak table" type. Instead, a DBMS handles weak entities by importing the owner table's primary key as a foreign key, combining it with the discriminator to create the primary key, and enforcing cascade deletion.
Step-by-step solution.
Handling a Weak Entity Set in DBMS:
ON DELETE CASCADE. If the owner entity tuple is deleted, all dependent weak entity tuples are automatically removed.Check.
SQL Schema Implementation Check:
CREATE TABLE section (
course_id VARCHAR(8),
sec_id VARCHAR(8),
semester VARCHAR(6),
year NUMERIC(4,0),
PRIMARY KEY (course_id, sec_id, semester, year),
FOREIGN KEY (course_id) REFERENCES course(course_id) ON DELETE CASCADE
);
The table schema directly demonstrates how the identifying foreign key combines with the discriminator to form the primary key.
Exam tip.
List the three clear database steps: primary key construction, table creation without relationship table, and cascading deletion.
Sources.
Topic: T02.5 · Design a full E-R diagram for a scenario · Section A
Question. Suppose you are recruited as a database specialist by the Rajshahi High-Tech authority to help them design a database for train e-ticketing system efficiently. Now think the regular features and draw an E-R diagram accordingly.
Answer.
What the examiner wants.
A realistic, domain-specific E-R diagram for an online railway ticketing system (6 marks). The diagram needs primary entities (Passenger, Ticket, Train, Station), realistic attributes, primary keys underlined, and proper relationship cardinalities.
Key idea.
A train ticketing system manages passengers buying tickets for specific trains traveling along routes made of stations. Tickets are the central transaction records linking passengers to trains.
Step-by-step solution.
System Requirements & Entities:
user_id (PK), name, nid, phone.ticket_no (PK), journey_date, seat_no, fare, class.train_no (PK), train_name, total_seats.station_code (PK), station_name, city.Relationships:
Books (1:N): A passenger books one or more tickets. Each ticket is booked by one passenger (descriptive attribute: booking_date).For_Train (N:1): Many tickets belong to a specific train. Each ticket is assigned to exactly one train.Stops_At (M:N): Trains stop at multiple stations, and stations service multiple trains. Descriptive attributes: arrival_time, dep_time.
Figure: Train E-Ticketing System E-R Diagram
Check.
Workflow validation:
Stops_At schedule).Books relationship produces a TICKET).For_Train relationship).Exam tip.
Write out the 4 entities and their keys in bullet points before drawing. This keeps the diagram structured and easy to read.
Sources.
Topic: T01.4 · Data abstraction levels, schemas and instances · Section A (Repeated question: Also asked in 2017 | Solved in T01)
Question. What is data abstraction? Describe the different level of data abstraction.
Answer.
What the examiner wants.
The definition and purpose of data abstraction (~1 mark), clear descriptions of all three abstraction levels (physical, logical, view) (~2 marks), and the architecture diagram (~1 mark).
Key idea.
Database systems use complex data structures to store information efficiently. Most users and application programmers do not understand storage pointers or disk block layouts. Data abstraction hides low-level complexity to provide a clean and intuitive interface.
Step-by-step solution.
Purpose of Data Abstraction:
A database contains complex data structures, storage blocks, and indexing schemes. Most end users and programmers are not trained in low-level storage details. Data abstraction hides this physical complexity. It simplifies user interactions, enforces security, and enables physical data independence.
Levels of Data Abstraction:
type instructor = record
ID : string;
name : string;
dept_name : string;
salary : integer;
end;
Figure: Three levels of data abstraction (Deck 01, Slide 14)
Variant for 2019 Q.2(a) (4 marks): Define data abstraction, describe the three levels, and include the diagram.
Variant for CT-01 Q.01 (5 marks): State the definition, explain the three levels, show the record example, and draw the diagram.
Check.
Quick level-matching test:
Exam tip.
Draw the three-tiered box diagram with multiple view boxes on top, the logical box in the middle, and the physical box at the bottom.
Sources.
Topic: T04.2 · Write RA queries on a given schema · Section A
Question.
Consider the following relational database.Patient (Patient_ID, Patient_name, Mobile)History (Patient_ID, Symptom, Date)Report (Parient_ID, Corona_center, Test_result)
Now write down the relational algebra (Not SQL) to find out the following queries.
(i) Find the names of those patients who have fever symptom.
(ii) Consider that if any patient has high-fever symptom he/she will be suspected as corona patient. Find out such maximum number of patients in a date.
(iii) Find out the mobile numbers of those patients who have provided samples in Rajshahi corona center and their results have become positive.
(iv) Find out the name of those patients who have high fever symptom but test result have become negative.
(Note: Printed as "Parient_ID" in Report schema in original question paper; refers to "Patient_ID")
Answer.
What the examiner wants.
Four relational algebra queries worth 2 marks each. Covers selection on joined tables and daily grouping with peak aggregation. Also tests multi-table filtering and set intersection between history and lab test reports.
Key idea.
Link patients to clinical records via Patient_ID. Natural joins equate common keys. For part (ii), group by Date and count patients, then find the global maximum of these daily totals.
Step-by-step solution.
Assumption: In relation Report, Parient_ID is a typographical misprint for Patient_ID.
(i) Names of patients who have fever symptom:
History where Symptom = "fever".Patient on Patient_ID.(ii) Maximum number of suspected patients (high-fever symptom) on a date:
Date and count the patients on each date:(iii) Mobile numbers of patients tested in Rajshahi corona center with positive results:
Report for center "Rajshahi" and test result "positive".Patient on Patient_ID.Mobile:(iv) Names of patients who have high fever symptom but negative test result:
Patient, and project their names:Short version for 2024 Q.5(a) (Sec B, 4 marks, CO2):
Answer parts (i) and (ii) only. Part (i) matches part (i) above. Part (ii) targets Rangpur instead of Rajshahi:
Check.
Suppose:
History: (P1, "high-fever", "2020-04-01"), (P2, "high-fever", "2020-04-01"), (P3, "high-fever", "2020-04-02").
Report: (P1, "Rajshahi", "negative"), (P2, "Rajshahi", "positive").
Part (ii): Count on 2020-04-01 is 2. Count on 2020-04-02 is 1. The max operation yields 2.
Part (iv): Thigh={P1,P2,P3}. Tneg={P1}. Intersection is {P1}. The query correctly retrieves P1's name.
Exam tip.
When a question repeats across years with only a city name swapped, the query structure is identical. Memorize the two-step pattern for daily extremes: group by date with count, then apply scalar max.
Sources.
[Lecture Deck 02 · Slides 11–29](../LectureSlides/02_Relational_Model.md)
[Textbook Ch. 2 §2.6](../Textbook/Chapter_02_Relational_Model/Chapter%2002%20-%20Introduction%20to%20the%20Relational%20Model.md)
Topic: T08.6 · Define normalization (and its importance) & 1NF / 2NF / 3NF · Section A
Question. What is normalization? Discuss 1NF and 2NF.
Answer.
What the examiner wants.
Definition of normalization (1 mark), detailed discussion of 1NF rules with a clear example (1.5 marks), and 2NF rules with a clear example (1.5 marks).
Key idea.
1NF requires that every cell holds one single value (no lists). 2NF requires 1NF plus that every non-key attribute depends on the whole key, not just half of it.
Step-by-step solution.
Normalization is the process of decomposing a relation schema into smaller schemas to minimize data redundancy and prevent insertion, deletion, and update anomalies.
Rules:
Example:
Violating 1NF:
| Student_ID | Name | Phone |
|---|---|---|
| S01 | Fahim | 01711, 01822 |
| S02 | Noor | 01933 |
Converted to 1NF (atomic rows):
| Student_ID | Name | Phone |
|---|---|---|
| S01 | Fahim | 01711 |
| S01 | Fahim | 01822 |
| S02 | Noor | 01933 |
PK: (Student_ID, Phone)
Rules:
Example:
Consider relation ENROLL(StudentID, CourseID, StudentName, Grade):
(StudentID, CourseID)(StudentID, CourseID) -> Grade (Full dependency)StudentID -> StudentName (Partial dependency on proper subset StudentID)Converted to 2NF (decompose to remove partial dependency):
STUDENT(StudentID, StudentName) with PK StudentIDENROLLMENT(StudentID, CourseID, Grade) with PK (StudentID, CourseID)Short version for 2018 Q.4(c) (4 marks): State the rules for 1NF (atomicity, no multi-valued attributes) with the phone number example. State the rules for 2NF (in 1NF, no partial dependencies) with the student course example.
Check.
Quick self-test:
StudentName partially dependent in ENROLL?StudentID is already enough to determine StudentName; CourseID is completely unnecessary.Exam tip.
Keep the examples minimal: use a 2-row table for 1NF and a 4-attribute relation for 2NF.
Sources.
Topic: T09.2 · Consistency property alone, with example · Section A
Question. Explain the consistency property of a database system with a proper example.
Answer.
What the examiner wants.
A dedicated discussion of the consistency property. The examiner looks for the distinction between explicit constraints and implicit application invariants, along with a concrete numerical example showing temporary internal inconsistency versus final restored consistency. Mark split: 1 mark for definition/types, 2 marks for the example.
Key idea.
Consistency means preserving truth and valid business invariants. While a transaction is running, the database can be temporarily inconsistent internally. But once the transaction finishes, consistency must be fully restored.
Step-by-step solution.
Definition:
The consistency property requires that executing a transaction in isolation preserves the consistency of the database. If the database starts in a valid state that satisfies all integrity rules, it must end in a valid state after the transaction completes.
Categories of Consistency Constraints:
CHECK constraints (such as balance >= 0).Example (Bank Transfer):
Let account A have $1000 and account B have $2000. The consistency invariant requires total funds to remain constant:
Transaction T1 transfers $50 from A to B:
Check.
Quick self-test:
Exam tip.
Explicitly state that temporary inconsistency during execution is normal and necessary. The requirement is that consistency is restored when the transaction finishes.
Sources.
Topic: T06.1 · Types of joins · Section A
Question. What is joining? Discuss each type of joining between two data tables with example.
Answer.
What the examiner wants.
A formal definition of a join operation in relational database systems (1 mark), followed by descriptions and examples of the main join types: Inner join, Left outer join, Right outer join, Full outer join, and Cross join (4 marks, approximately 1 mark per join type).
Key idea.
A join operation combines tuples from two tables into a single result relation. It checks matching values in specified columns. An inner join keeps only matching rows. An outer join retains matching rows plus unmatched rows from one or both tables by padding empty attributes with NULL. A cross join pairs every row from the first table with every row from the second table.
Step-by-step solution.
Definition of Joining:
A join operation takes two relations and combines them into one relation based on a matching condition. It acts as a Cartesian product followed by a selection predicate and projection.
Figure: Join types and join conditions (Deck 04, Slide 4)
Example Base Tables:
Table course:
| course_id | title | dept_name | credits |
|---|---|---|---|
| BIO-301 | Genetics | Biology | 4 |
| CS-190 | Game Design | Comp. Sci. | 4 |
| CS-315 | Robotics | Comp. Sci. | 3 |
Table prereq:
| course_id | prereq_id |
|---|---|
| BIO-301 | BIO-101 |
| CS-190 | CS-101 |
| CS-347 | CS-101 |
Retains only tuples that satisfy the join condition in both tables. Unmatched rows are dropped.
SELECT course.course_id, title, dept_name, prereq_id
FROM course
INNER JOIN prereq ON course.course_id = prereq.course_id;
Relational algebra:
course⋈prereqResult:
| course_id | title | dept_name | prereq_id |
|---|---|---|---|
| BIO-301 | Genetics | Biology | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | CS-101 |
Preserves every row from the left table (course). Fills right-table attributes with NULL when no match exists.
SELECT course.course_id, title, dept_name, prereq_id
FROM course
LEFT JOIN prereq ON course.course_id = prereq.course_id;
Relational algebra:
course⟕prereqResult:
| course_id | title | dept_name | prereq_id |
|---|---|---|---|
| BIO-301 | Genetics | Biology | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | CS-101 |
| CS-315 | Robotics | Comp. Sci. | NULL |
Preserves every row from the right table (prereq). Fills left-table attributes with NULL when no match exists.
SELECT prereq.course_id, title, dept_name, prereq_id
FROM course
RIGHT JOIN prereq ON course.course_id = prereq.course_id;
Relational algebra:
course⟖prereqResult:
| course_id | title | dept_name | prereq_id |
|---|---|---|---|
| BIO-301 | Genetics | Biology | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | CS-101 |
| CS-347 | NULL | NULL | CS-101 |
Retains all rows from both tables. It pairs matching rows and fills missing values with NULL. MySQL emulates it using UNION.
SELECT course.course_id, title, dept_name, prereq_id
FROM course
LEFT JOIN prereq ON course.course_id = prereq.course_id
UNION
SELECT prereq.course_id, title, dept_name, prereq_id
FROM course
RIGHT JOIN prereq ON course.course_id = prereq.course_id;
Relational algebra:
course⟗prereqResult:
| course_id | title | dept_name | prereq_id |
|---|---|---|---|
| BIO-301 | Genetics | Biology | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | CS-101 |
| CS-315 | Robotics | Comp. Sci. | NULL |
| CS-347 | NULL | NULL | CS-101 |
Combines each row of the first table with every row of the second table without any condition.
SELECT *
FROM course
CROSS JOIN prereq;
Relational algebra:
course×prereqIt returns 3×3=9 rows.
Variant for 2023 Q.5(c) (4 marks): The same definition and four outer and inner join examples answer the question.
Check.
Quick self-test:
prereq.NULL.FULL OUTER JOIN syntax directly?FULL OUTER JOIN syntax, so we combine LEFT JOIN and RIGHT JOIN with UNION.Exam tip.
Use one small pair of 3-row tables across all join types. This saves drawing time and lets the examiner verify row counts instantly.
Sources.
Topic: [[Topicwise_answers_explaination/T10_Serializability.md#T10.4 · Build serializable/non-serializable schedules (T1,T2 with "if A = 0 then B := B+1")|T10.4 · Build serializable/non-serializable schedules (T1,T2 with "if A = 0 then B := B+1")]] · Section A
Question.
What is concurrency control? Consider the following two transactions.
T1:read (P);read (Q);if P=10 then Q:=Q-5;write (Q);
T2:read (Q);read (P);if Q=10 then P:=P+5;write (P);
Let the consistency requirement be P=5 or Q=5 with P=Q=5 the initial values.
(i) Show a concurrent execution of T1 and T2 that produces a serializable schedule.
(ii) Is there a concurrent execution of T1 and T2 that produces a serializable schedule?
(Note: In the printed question paper, sub-question (ii) is printed identically to (i) as "Is there a concurrent execution of T1 and T2 that produces a serializable schedule?")
Answer.
What the examiner wants. Definition of concurrency control (2 marks), handling of the printed transaction scenario with initial values and IF conditions (2.5 marks), and analysis of serializable vs non-serializable concurrent schedules (2.5 marks).
Key idea. Concurrency control ensures database consistency when multiple transactions run simultaneously. The given scenario is adapted from Silberschatz Exercise 17.15, but has typographical errors in the question paper. We address the question as printed, and also explain the textbook intent.
Step-by-step solution.
Concurrency control is the DBMS subsystem that manages simultaneous execution of transactions on a shared database. Its main goals are:
Assumption: Sub-question (ii) repeats (i) due to a printing error, and the IF conditions test P = 10 / Q = 10 while initial values are P = Q = 5; we answer as printed, and also show the intended reading modeled on the Silberschatz consistency exercise.
P = 10 evaluates to false. Q is not decremented. T1 writes Q=5.Q = 10 evaluates to false. P is not incremented. T2 writes P=5.A concurrent schedule is serializable if its precedence graph is acyclic. We achieve this by letting one transaction complete its conflicting operations on the shared variables before the other begins:
| Step | T1 | T2 | Local Actions |
|---|---|---|---|
| 1 | read(P); | T1 reads P=5 | |
| 2 | read(Q); | T1 reads Q=5 | |
| 3 | if P=10 then Q:=Q-5;write(Q); | Condition false; writes Q=5 | |
| 4 | read(Q); | T2 reads Q=5 | |
| 5 | read(P); | T2 reads P=5 | |
| 6 | if Q=10 then P:=P+5;write(P); | Condition false; writes P=5 |
Conflict Analysis:
The precedence graph is acyclic. The schedule is conflict serializable, with equivalent serial order:
⟨T1,T2⟩Sub-question (ii) repeats (i) due to a misprint. In the original Silberschatz problem, sub-question (ii) asks: "Is there an interleaved concurrent execution of T1 and T2 that produces a non-serializable schedule?"
Consider an interleaved execution where both transactions read before writing:
| Step | T1 | T2 |
|---|---|---|
| 1 | read(P); | |
| 2 | read(Q); | |
| 3 | read(Q); | |
| 4 | read(P); | |
| 5 | write(Q); | |
| 6 | write(P); |

Conflicts:
The precedence graph contains a directed cycle:
T1⟷T2Because of this cycle, this interleaved schedule is NOT conflict serializable.
Also, if the IF conditions were intended to test initial values (if P = 5 then Q := Q - 5 and if Q = 5 then P := P + 5), this interleaving would produce P=10 and Q=0, violating the consistency requirement P=5∨Q=5.
Check.
Exam tip. Always answer both what is printed and what was clearly intended. This ensures you receive full credit regardless of which marking scheme the examiner follows.
Sources.
Topic: T12.1 · Failure classification, precautions, recovery methods · Section A
Question. How many ways a DBMS could be failed? What precautions should be taken considering the failure of DBMS and point out the recovery methods.
Answer.
What the examiner wants.
A three-part answer covering failure modes (2 marks), runtime precautions (1.5 marks), and recovery methods (1.5 marks).
Key idea.
A database handles failures in two distinct stages. First, it takes proactive precautions during normal runtime (logging, RAID, battery backups). Second, it executes reactive recovery algorithms (undo/redo, checkpoints) after a failure occurs.
Step-by-step solution.
A DBMS can fail in three primary ways:
Short version for 2024 Q.3(b) (CO1, 4 marks): Provide the same three sections in concise bullet points to fit the 4-mark time limit.
Check.
Quick self-test:
Exam tip.
Use three distinct headings matching the prompt: Failures, Precautions, and Recovery Methods.
Sources.
Topic: T05.1 · What SQL is; SQL short note · Section B
Question. Write a short note on SQL.
Answer.
What the examiner wants.
The formal full name of SQL, its original historical background (IBM System R), its declarative paradigm, and its major sub-languages (DDL, DML, DCL/TCL). The mark split is 1 mark for the core definition and role, and 1 mark for key functional parts.
Key idea.
Unlike procedural programming languages (C, Java) where you write explicit loops to access disk records, SQL is non-procedural (declarative). You describe the desired target relation using set operations and relational predicates. The internal database query processor handles the physical indexing and file scanning.
Step-by-step solution.
SQL (Structured Query Language) is the standard declarative computer language used to define, query, and manipulate data in relational database management systems (RDBMS). It was originally developed at IBM in the 1970s for System R.
Key parts of SQL include:
CREATE, ALTER, DROP).SELECT, INSERT, UPDATE, DELETE).GRANT, REVOKE) and transaction boundaries (COMMIT, ROLLBACK).SQL is declarative. The user specifies what result is wanted rather than how to calculate it.
Check.
Quick self-test:
PRIMARY KEY and NOT NULL constraints inside CREATE TABLE.Exam tip.
For 2 marks, keep the response under 80 words. Name the language, define its declarative property, and bullet DDL, DML, and DCL/TCL.
Sources.
Deck 03 · Slides 3–4, Textbook Ch. 3 §3.1–3.2.
Topic: T05.7 · Multi-table business-schema query sets (MySQL): Covid, Company, Insurance, E-commerce · Section B
Question.
Consider the following relational database.Patient (Patient_ID, Patient_name, Mobile)History (Patient_ID, Symptom, Date)Report (Parient_ID, Corona_center, Test_result)
Now write down the SQL (Not Algebra) to find out the following queries.
(i) Find the names of those patients who have-fever symptom.
(ii) Consider that if any patient has high fever symptom he/she will be suspected as corona patient. Find out such maximum number of patients in a date.
(iii) Find out the mobile numbers of those patients who have provided samples in Rajshahi corona center and their results have become positive.
(iv) Find out the name of those patients who have high fever symptom but test result have become negative.
(Note: In the physical question paper, SECTION-B heading and Q.5(a)–(b) appear at the bottom of Page 1; Q.5(c) continues at the top of Page 2)
(Note: Printed as "Parient_ID" in Report schema in original question paper; refers to "Patient_ID")
Answer.
What the examiner wants.
Four relational database queries across medical tracking relations (2 marks each):
LIKE '%fever%') across joined tables.Key idea.
Part (ii) requires finding the peak daily suspect count. Since standard SQL does not allow nested aggregate functions like MAX(COUNT(*)), the daily counts must be computed inside a subquery in the FROM clause, after which MAX() is applied to the derived column.
Step-by-step solution.
Assumption: "Parient_ID" in the Report table is a typographical misprint for Patient_ID and joins with Patient.Patient_ID.
(i) Names of patients who have fever symptom:
SELECT DISTINCT p.Patient_name
FROM Patient p
JOIN History h ON p.Patient_ID = h.Patient_ID
WHERE h.Symptom LIKE '%fever%';
(ii) Maximum number of high-fever patients recorded on a single date:
SELECT MAX(daily_count) AS max_patients
FROM (
SELECT Date, COUNT(DISTINCT Patient_ID) AS daily_count
FROM History
WHERE Symptom = 'high fever'
GROUP BY Date
) AS daily_summary;
(Alternative returning the specific date with the peak count: SELECT Date, COUNT(DISTINCT Patient_ID) AS patient_count FROM History WHERE Symptom = 'high fever' GROUP BY Date ORDER BY patient_count DESC LIMIT 1;)
(iii) Mobile numbers of patients tested in Rajshahi corona center with positive result:
SELECT DISTINCT p.Mobile
FROM Patient p
JOIN Report r ON p.Patient_ID = r.Parient_ID
WHERE r.Corona_center = 'Rajshahi'
AND r.Test_result = 'positive';
(iv) Names of patients with high fever symptom whose test result is negative:
SELECT DISTINCT p.Patient_name
FROM Patient p
JOIN History h ON p.Patient_ID = h.Patient_ID
JOIN Report r ON p.Patient_ID = r.Parient_ID
WHERE h.Symptom = 'high fever'
AND r.Test_result = 'negative';
Check.
Trace with sample medical records:
('2020-04-01', 3) and ('2020-04-02', 5).MAX(daily_count) evaluates to 5.Exam tip.
When an aggregate of an aggregate is needed, wrap the initial GROUP BY query in the FROM clause with an alias (e.g., FROM (...) AS daily_summary).
Sources.
Deck 03 · Slides 18, 22, 30–32, 48–49, Textbook Ch. 3 §3.4, §3.7, §3.8.
Topic: T05.2 · DDL + DML warm-up: CREATE, INSERT, ALTER ... ADD, UPDATE, DELETE, rename, filter · Section B
Question.
Write down the SQL queries to create the following tables.Answer.
What the examiner wants.
Three complete CREATE TABLE statements demonstrating correct data type assignment, primary keys, and foreign key references linking dependent tables to the master Patient relation.
Key idea.
Patient is an independent master relation. History and Report are dependent relations that track observations and test reports respectively. Because a patient can report symptoms across multiple dates, History requires a composite primary key (Patient_ID, Symptom, Date).
Step-by-step solution.
Assumption: "Parient_ID" in the Report table is a typographical misprint for Patient_ID and serves as a foreign key referencing the Patient table.
CREATE TABLE Patient (
Patient_ID INT PRIMARY KEY,
Patient_name VARCHAR(50),
Mobile VARCHAR(15)
);
CREATE TABLE History (
Patient_ID INT,
Symptom VARCHAR(50),
Date DATE,
PRIMARY KEY (Patient_ID, Symptom, Date),
FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID)
);
CREATE TABLE Report (
Patient_ID INT PRIMARY KEY,
Corona_center VARCHAR(50),
Test_result VARCHAR(20),
FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID)
);
Check.
Relational integrity verification:
History, Report) define foreign keys pointing to Patient(Patient_ID).Patient must be created first before child tables execute their foreign key constraints.Exam tip.
Always define the parent table before the referencing child tables so foreign key dependencies resolve cleanly.
Sources.
Deck 03 · Slides 7–9, Textbook Ch. 3 §3.2.
Topic: T08.1 · Why normalize: redundancy and insert/update/delete anomalies · Section B
Question.
Consider the following data tables.
Student
| Roll | Name | Dept | Sub Code | Sub Grade | Reg Sub Code |
|---|---|---|---|---|---|
| 1710001 | Mr. A | ECE | ECE-2103 | A+ | ECE-2103 ECE-2107 |
| 1710002 | Mr. B | ECE | ECE-2107 | A | ECE-2103 ECE-2107 |
| 1710003 | Mr. C | ECE | ECE-2103 | A- | ECE-2103 |
| 1710004 | Mr. D | ECE | ECE-2107 | A+ | ECE-2107 |
| 1710001 | Mr. A | ECE | ECE-2107 | A- | ECE-2103 ECE-2107 |
| 1710002 | Mr. B | ECE | ECE-2103 | A+ | ECE-2103 ECE-2107 |
Answer.
What the examiner wants.
Direct answers to all three parts: (i) evaluation of storage wastage due to repeated student attributes and multi-valued course lists (2 marks); (ii) analysis of update anomalies and inconsistencies (2 marks); (iii) analysis of deletion challenges including string manipulation and loss of records for single-course students (2 marks).
Key idea.
The table mixes three different concepts in one place: student demographics, individual course grades, and registered course lists. Even worse, Reg Sub Code stores multiple course codes inside a single cell. This design wastes storage and creates severe data manipulation headaches.
Step-by-step solution.
The table is highly space-inefficient for three reasons:
Name ("Mr. A", "Mr. B") and Dept ("ECE") are repeated across multiple rows for the same Roll.Reg Sub Code contains multi-valued lists (e.g., ECE-2103, ECE-2107). Storing this composite list in every row for a student wastes substantial storage.Updating any student-level or course-level attribute causes an update anomaly:
1710001 must be updated.Reg Sub Code must be modified across every row for that student.1710001 could end up with different department names or conflicting registered course lists in different rows.If asked to delete 'ECE-2107' from the registered course list while preserving all other data:
Reg Sub Code across all their records and strip 'ECE-2107'. This is slow and error-prone.Reg Sub Code to NULL leaves an incomplete record.Check.
Quick self-test:
Reg Sub Code non-atomic?ECE-2103 and ECE-2107) separated by line breaks into a single table cell.ECE-2107?1710004 (Mr. D), because ECE-2107 is his only course.Exam tip.
Number your answers exactly as (i), (ii), and (iii). Cite specific roll numbers (e.g., 1710001, 1710004) from the given table in your arguments.
Sources.
Topic: T03.2 · Keys: super / candidate / primary / alternate / composite / foreign · Section B
Question. Discuss the different keys in DBMS. Write down the importance and use of foreign key with example.
Answer.
What the examiner wants.
A comprehensive answer covering all major DBMS key types (~3 marks) and a detailed discussion of foreign key role, importance, cascading actions, and an example (~3 marks).
Key idea.
Keys organize tables and preserve database integrity. The foreign key links independent relations together. It prevents orphan records by requiring every referenced value to exist in a parent relation.
Step-by-step solution.
1. Different Keys in DBMS:
2. Importance and Use of Foreign Key:
CASCADE, SET NULL, RESTRICT). When parent records change, child records update or delete automatically.Example:
Consider two relations:
Here, dept_name in Student is a foreign key referencing dept_name in Department.
'ECE', 'ECE' must exist in Department.dept_name = 'Civil', and 'Civil' is not in Department, the DBMS rejects the insert. This protects database integrity.Check.
Referential integrity trace:
Department('ECE', 'Academic Building 2', 500000.00).Student(101, 'Akib', 'akib@gmail.com', 'ECE') succeeds because 'ECE' exists in Department.Student(102, 'Shuvo', 'shuvo@gmail.com', 'Civil') fails if 'Civil' is absent from Department.Exam tip.
Divide your answer into two clear sections: "1. Different Keys in DBMS" and "2. Importance and Use of Foreign Key". This matches the two questions in the prompt.
Sources.
Topic: T05.5 · Aggregation queries: GROUP BY + HAVING, CGPA, extremes without LIMIT · Section B
Question.
Considering the following data tables (Student, GPA, Credits) answer (i), (ii), (iii), & (iv).
Student
| St_ID | St Name |
|---|---|
| 2010001 | Abdullah |
| 2010002 | Ahmad |
| 2010003 | Mohammad |
| 2010004 | Muaz |
| 2010005 | Minhaz |
| St_ID | Sub_Code | gpa |
|---|---|---|
| 2010001 | ECE-1103 | 3.00 |
| 2010002 | ECE-1107 | 3.25 |
| 2010004 | ECE-1103 | 4.00 |
| 2010005 | ECE-1103 | 4.00 |
| 2010003 | ECE-1107 | 3.75 |
| Sub_Code | Credit |
|---|---|
| ECE-1103 | 3.00 |
| ECE-1107 | 3.00 |
Answer.
What the examiner wants.
Four distinct queries testing fundamental SQL patterns (3 marks each):
WHERE gpa = (SELECT MIN(gpa) ...).LIKE 'A%' joined across tables.MAX(gpa) grouped by subject code.Key idea.
Examining extreme values (lowest GPA) without hardcoding requires a subquery to locate the dynamic minimum. Calculating CGPA requires joining three tables (Student, GPA, Credit) so that course credits and grade points align by subject code while grouping by student.
Step-by-step solution.
(i) List of students who got the lowest GPA:
SELECT s.St_ID, s.`St Name`, g.Sub_Code, g.gpa
FROM Student s
JOIN GPA g ON s.St_ID = g.St_ID
WHERE g.gpa = (
SELECT MIN(gpa)
FROM GPA
);
(ii) Registered subjects of students whose name starts with "A":
SELECT DISTINCT s.St_ID, s.`St Name`, g.Sub_Code
FROM Student s
JOIN GPA g ON s.St_ID = g.St_ID
WHERE s.`St Name` LIKE 'A%';
(iii) Calculate CGPA of each student:
SELECT s.St_ID, s.`St Name`,
SUM(g.gpa * c.Credit) / SUM(c.Credit) AS cgpa
FROM Student s
JOIN GPA g ON s.St_ID = g.St_ID
JOIN Credit c ON g.Sub_Code = c.Sub_Code
GROUP BY s.St_ID, s.`St Name`;
(iv) Each subject code and corresponding highest GPA:
SELECT Sub_Code,
MAX(gpa) AS highest_gpa
FROM GPA
GROUP BY Sub_Code;
Check.
Verification against the provided table data:
GPA table is 3.00. Subquery returns 3.00. Result: (2010001, 'Abdullah', 'ECE-1103', 3.00).2010001) and Ahmad (2010002). Registered subjects: Abdullah ⟹ ECE-1103; Ahmad ⟹ ECE-1107.Exam tip.
When column names contain spaces in the question paper, wrap them in backticks (`St Name`) in MySQL to maintain valid syntax.
Sources.
Deck 03 · Slides 22, 30–33, 35, Textbook Ch. 3 §3.4, §3.7, §3.8.
Topic: T05.4 · Aggregate functions (theory) · Section B
Question. Discuss about four aggregate functions.
Answer.
What the examiner wants.
A clear definition of what an aggregate function is in SQL, followed by four distinct functions (COUNT, SUM, AVG, MIN/MAX) with their purpose, allowed data types, and a brief SQL example (1 mark per function).
Key idea.
Unlike scalar operations that transform each row independently, aggregate functions collapse an entire column (or group of rows) into a single scalar value. SQL aggregate functions automatically ignore null values, with the single exception of COUNT(*).
Step-by-step solution.
An aggregate function takes a collection (multiset) of values from a specified attribute and computes a single summarizing scalar value. SQL ignores null values during aggregation (except for COUNT(*)).
Four standard aggregate functions:
COUNT():COUNT(*) counts all rows in the relation, including duplicates and nulls.COUNT(A) counts non-null values of attribute A.SELECT COUNT(*) FROM instructor;
SUM():SELECT SUM(salary) FROM instructor;
AVG():SELECT AVG(salary) FROM instructor WHERE dept_name = 'ECE';
MIN() and MAX():SELECT MIN(salary) AS min_sal, MAX(salary) AS max_sal FROM instructor;
Check.
Quick self-test:
COUNT(*) differ from COUNT(dept_name)?COUNT(*) returns the total row count including rows with null values, while COUNT(dept_name) counts only rows where dept_name is non-null.AVG(salary) is applied to an empty table?NULL.Exam tip.
For theory aggregate questions, always write the mathematical purpose and one line of valid SQL for each function.
Sources.
Deck 03 · Slides 30–31, Textbook Ch. 3 §3.7.
Topic: T05.6 · Subqueries theory ("two examples"): IN, SOME/ALL, EXISTS, scalar, correlated, WITH · Section B (Repeated question: Also asked in 2024 | Solved in T05)
Question. Write down two examples of using sub-queries.
Answer.
What the examiner wants.
A conceptual explanation of what a subquery is in SQL, followed by two well-structured, distinct query examples (e.g., set membership IN and scalar aggregate comparison) with explanations of how the inner and outer queries interact (2 marks for theory/structure, 1 mark per example).
Key idea.
A subquery embeds one SELECT statement inside another. Instead of writing multiple separate programs to retrieve intermediate data, a subquery passes intermediate sets or single scalar values directly to the outer query's predicates.
Step-by-step solution.
Explanation: A subquery (or nested query) is a SELECT statement embedded inside another SQL statement (the outer query). It can appear in the WHERE clause to filter tuples, in the FROM clause as a temporary derived relation, or in the SELECT clause as a scalar expression. Subqueries allow multi-step data retrieval in a single query.
Example 1: Set Membership Subquery (IN)
Find all courses offered in Fall 2017 that were also offered in Spring 2018:
SELECT DISTINCT course_id
FROM section
WHERE semester = 'Fall' AND year = 2017
AND course_id IN (
SELECT course_id
FROM section
WHERE semester = 'Spring' AND year = 2018
);
The inner subquery generates the set of courses running in Spring 2018. The outer query checks whether Fall 2017 courses belong to that generated set.
Example 2: Scalar Comparison Subquery (AVG)
Find instructors whose salary is higher than the average salary of all instructors:
SELECT name, salary
FROM instructor
WHERE salary > (
SELECT AVG(salary)
FROM instructor
);
The inner query computes a single numeric value (the overall average salary). The outer query evaluates the > predicate against this scalar value for each instructor.
Variant for 2019 Q.8(b) (4 marks): Presenting the two SQL examples with their purpose answers the question.
Check.
Execution mechanisms:
IN), the subquery produces a unary relation {c1,c2,…}. The outer query performs membership testing (t∈R).scalar), the subquery reduces to a single numerical value (e.g., 65,000). The outer query compares each instructor's salary attribute directly against this scalar.Exam tip.
Pair one set membership example (IN) with one aggregate scalar example (AVG) to demonstrate broad SQL competence.
Sources.
Deck 03 · Slides 35–43, 52, Textbook Ch. 3 §3.8.
Topic: T05.8 · Short notes: ON DELETE CASCADE, GROUP BY, ORDER BY, AS · Section B (Repeated question: Also asked in 2024 | Solved in T05)
Question.
Write short note on the following statements.
(i) ON CASCADE DELETE.
(ii) Group By.
Answer.
What the examiner wants.
Concise technical descriptions, purpose, and standard SQL syntax/examples for four fundamental SQL clauses and constraint actions (1 mark each).
Key idea.
Each term serves a distinct role in relational data management: ON DELETE CASCADE governs referential integrity maintenance; GROUP BY partitions data for summary aggregation; ORDER BY controls output presentation order; AS introduces aliasing for projection expressions and relation names.
Step-by-step solution.
i) ON DELETE CASCADE (printed as "ON CASCADE DELETE"):
A foreign key referential integrity action. When a tuple in the parent table is deleted, the DBMS automatically deletes all corresponding referencing tuples in the child table. This maintains referential integrity and prevents orphaned records.
CREATE TABLE section (
course_id VARCHAR(8),
sec_id VARCHAR(8),
semester VARCHAR(6),
year NUMERIC(4, 0),
PRIMARY KEY (course_id, sec_id, semester, year),
FOREIGN KEY (course_id) REFERENCES course(course_id)
ON DELETE CASCADE
);
ii) GROUP BY:
An SQL clause used to partition table rows into distinct groups having identical values in specified columns. Aggregate functions (COUNT, SUM, AVG, MIN, MAX) then compute summary statistics for each individual group.
SELECT dept_name, AVG(salary) AS avg_sal
FROM instructor
GROUP BY dept_name;
iii) ORDER BY:
An SQL clause that sorts query result rows in ascending (ASC, default) or descending (DESC) order based on one or more attributes. Multiple sort keys break ties sequentially.
SELECT name, salary
FROM instructor
ORDER BY salary DESC, name ASC;
iv) AS:
An SQL keyword used to define an alias (an alternative temporary name). It can rename an attribute or computed expression in the SELECT clause for readability, or rename a table in the FROM clause to shorten table references and enable self-joins.
SELECT salary * 1.15 AS revised_salary
FROM employee AS e;
Short version for 2019 Q.8(c) (4 marks): Provide parts (i) and (ii).
Short version for 2023 Q.6(c) (2 marks): Provide part (i) with definition, syntax, and effect.
Check.
Referential trace of ON DELETE CASCADE:
department.course have dept_name = 'Biology'.department via DELETE FROM department WHERE dept_name = 'Biology' automatically removes the three referencing courses from course.Exam tip.
For short notes on SQL statements, always supply both the formal definition and a minimal code snippet illustrating syntax.
Sources.
Deck 03 · Slides 8, 20, 24, 32, Deck 04 · Slide 4, Textbook Ch. 3 §3.4, §3.6, §3.7, Textbook Ch. 4 §4.4.5.
← Prev: 2018 | Exam-Style Layer | Original Question Paper | Next: 2020 →