51.6 KB · commit 40bb182
| year | 2020 |
|---|---|
| exam | B.Sc. Engineering 2nd Year Even Semester Examination, 2020 |
| course_code | ECE 2215 |
| course_title | Database Systems |
| full_marks | 72 |
| time | 3 Hours |
| layer | exam-style |
← Prev: 2019 | Explanation Layer | Original Question Paper | Next: 2021 →
Topic: T01.3 · Functions of the DBA and relation schema · Section A
Question. What are the five main functions of a database administrator? What is relation schema?
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: T01.7 · Two-tier vs three-tier architecture · Section A
Question. Differentiate between the two-tier architecture and three-tier architecture of database. Which is better suited for web application? Why?
Answer.
Differences between Two-Tier and Three-Tier Architectures:
| Feature | Two-Tier Architecture | Three-Tier Architecture |
|---|---|---|
| Application Placement | The application logic resides entirely on the client machine. | The client holds only the presentation layer. Application logic resides on an intermediate application server. |
| Database Communication | The client invokes database system calls directly over the network (using ODBC or JDBC). | The client communicates with the application server, which in turn contacts the database system. |
| Client Overhead | Thick (fat) client. Requires database drivers and business code installed on each client. | Thin client. Runs in a web browser or simple mobile interface. |
Figure: Two-tier and three-tier database architectures (Deck 01, Slide 30)
Web Application Choice & Reason:
Three-tier architecture is better suited for web applications.
Topic: T02.3 · Mapping cardinality and participation constraints · Section A
Question. What is mapping cardinalities? Define different types of cardinalities.
Answer.
Mapping Cardinality:
Mapping cardinality specifies how many entities from one entity set can be associated with entities from another entity set through a binary relationship set.
Types of Mapping Cardinalities:
One-to-One (1:1):
dept_head).One-to-Many (1:N):
Many-to-One (N:1):
Many-to-Many (M:N):
See also: 2018 Q.1(c) (tests participation constraints) and CT-02 Q.02 (identifies entities, keys, relationships, and cardinalities).
Topic: T04.2 · Write RA queries on a given schema · Section A
Question.
Consider the following relation schema:
person(id, name, age)
vaccine(id, center, dose_no, date)
Now give expression in relational algebra to express-
(i) Find the names of all persons who are adult.
(ii) Find the names of all persons who have taken the 1st dose only.
(iii) Find the details of all persons who were given vaccine from "RMC" center and completed 2nd dose.
Answer.
Assumption: An adult is defined as a person with age≥18. The attribute vaccine.id references person.id.
(i) Names of all adult persons:
Πname(σage≥18(person))(ii) Names of all persons who have taken the 1st dose only:
Subtract persons who took dose 2 from persons who took dose 1, then join with person to get names:
Tdose1←Πid(σdose_no=1(vaccine)) Tdose2←Πid(σdose_no=2(vaccine)) Tonly1←Tdose1−Tdose2 Πname(person⋈Tonly1)Equivalently, written as a single expression:
Πname(person⋈(Πid(σdose_no=1(vaccine))−Πid(σdose_no=2(vaccine))))(iii) Details of all persons vaccinated from "RMC" center who completed 2nd dose:
Select vaccine records matching center "RMC" and dose 2, then join with person:
Trmc2←σcenter="RMC"∧dose_no=2(vaccine) person⋈Trmc2To display person attributes only:
Πperson.id,name,age(person⋈Trmc2)Topic: T03.2 · Keys: super / candidate / primary / alternate / composite / foreign · Section A
Question. Write short note about: Super Key, Candidate Key, Primary Key, and Foreign Key.
Answer.
1. Super Key:
2. Candidate Key:
3. Primary Key:
NOT NULL). It should rarely or never change.4. Foreign Key:
dept_name in Student is a foreign key referencing Department(dept_name).Topic: T02.4 · Weak vs strong entity sets · Section A (Repeated question: Also asked in 2018 | Solved in T02)
Question. Explain the difference between a weak and a 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.
Topic: T02.8 · EER: aggregation · Section A (Repeated question: Also asked in 2018 | Solved in T02)
Question. What is aggregation in ER-model design?
Answer.
Definition:
Aggregation is an abstraction in E-R modeling through which a relationship set is treated as a higher-level abstract entity set. This allows the relationship itself to participate in further relationships with other entity sets without duplicating attributes.
Figure: Aggregation Representation in E-R Diagram (Deck 05, Slide 59)
Two Examples Where Aggregation is Useful:
Student Project Evaluation:
The ternary relationship proj_guide associates student, instructor, and project. To record an evaluation for that specific guidance assignment, treating proj_guide as an aggregate entity avoids creating an overlapping ternary relationship. evaluation links directly to the aggregate proj_guide through the relationship eval_for.
Employee Project Monitoring:
Employees work on projects via the relationship Works_On. A manager needs to monitor that specific work assignment. By aggregating Works_On into an entity, the manager can participate in a relationship Monitors directly with the aggregate entity (Employee, Project).
Short version for 2020 Q.3(a) (2 marks):
Give the definition of aggregation and describe Example 1 (proj_guide with eval_for) in 2 lines.
Topic: T05.7 · Multi-table business-schema query sets (MySQL): Covid, Company, Insurance, E-commerce · Section A
Question.
Consider the following company database schema.
employee(ssn, fname, lname, DoB, Address, Sex, Salary, dept_no)
department(dnumber, dname, mgr_ssn, mgr_start_date)
dept_location(dnumber, dlocation)
project(pnumber, pname, dnum)
works_on(essn, pno, hours)
dependent(essn, dependent_name, Sex, DoB, relationship)
Now write down the MySQL query for the followings.
(i) For each department whose average salary is more than $30,000, retrieve the department_name and the number of employees working for that department.
(ii) Find the names of all employees who are working on project number "5" and are from the same department.
(iii) Find the number of dependent people of those employees who are from "H&R" department.
Answer.
(i) Department name and employee count for departments with average salary > $30,000:
SELECT d.dname AS department_name,
COUNT(e.ssn) AS number_of_employees
FROM department d
JOIN employee e ON d.dnumber = e.dept_no
GROUP BY d.dnumber, d.dname
HAVING AVG(e.Salary) > 30000;
(ii) Names of employees working on project 5 who belong to the department controlling project 5:
Assumption: "from the same department" means the employee's department matches the department controlling project 5 (e.dept_no = p.dnum).
SELECT e.fname, e.lname
FROM employee e
JOIN works_on w ON e.ssn = w.essn
JOIN project p ON w.pno = p.pnumber
WHERE p.pnumber = 5
AND e.dept_no = p.dnum;
(iii) Total number of dependents for employees in the "H&R" department:
SELECT COUNT(dp.dependent_name) AS total_dependents
FROM dependent dp
JOIN employee e ON dp.essn = e.ssn
JOIN department d ON e.dept_no = d.dnumber
WHERE d.dname = 'H&R';
Topic: T13.2 · SQL injection: how it works and prevention · Section A (Repeated question: Also asked in 2021 | Solved in T13)
Question. What is an SQL injection attack? Explain how it works and what precautions must be taken to prevent SQL injection 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: T04.5 · Domain relational calculus · Section A
Question.
Let that, R=(A,B,C) and r1, r2 both be relations on the schema R. Give an expression in the domain relational calculus that is equivalent to each of the followings.
(i) πA(r1)
(ii) r1∪r2
(iii) r1∩r2
Answer.
Let relation instances r1 and r2 consist of tuples with three domain variables ⟨a,b,c⟩ corresponding to attributes (A,B,C).
(i) Domain calculus for πA(r1):
Project attribute A by existentially quantifying domain variables b and c:
{⟨a⟩∣∃b,c(⟨a,b,c⟩∈r1)}(ii) Domain calculus for r1∪r2:
A tuple belongs to the union if it belongs to r1, or to r2, or to both:
{⟨a,b,c⟩∣⟨a,b,c⟩∈r1∨⟨a,b,c⟩∈r2}(iii) Domain calculus for r1∩r2:
A tuple belongs to the intersection if it belongs to both r1 and r2:
{⟨a,b,c⟩∣⟨a,b,c⟩∈r1∧⟨a,b,c⟩∈r2}Topic: T06.2 · Join outcome tables · Section A
Question.
Consider the following tables:
Courses
| Teacher
|
Answer.
Assumption: The attribute "t code" is the common join key between Courses and Teacher.
The common attribute is t code. In SQL statements, it is written as `t code`.
Matches tuples where t code is identical and outputs one copy of t code.
Relational algebra:
Courses⋈TeacherMySQL query:
SELECT Code, Series, `t code`, Designation
FROM Courses
NATURAL JOIN Teacher;
Outcome Table (4 rows):
| Code | Series | t code | Designation |
|---|---|---|---|
| ECE 2215 | 2017 | T1 | Head |
| ECE 4127 | 2016 | T2 | Professor |
| ECE 1203 | 2019 | T3 | Lecturer |
| ECE 2219 | 2017 | T2 | Professor |
Explanation: Every course has a matching teacher. T4 in Teacher has no course, so it is omitted.
Preserves all rows from the left table (Courses). Missing right attributes get NULL.
Relational algebra:
Courses⟕TeacherMySQL query:
SELECT Courses.Code, Courses.Series, Courses.`t code`, Teacher.Designation
FROM Courses
LEFT JOIN Teacher ON Courses.`t code` = Teacher.`t code`;
Outcome Table (4 rows):
| Code | Series | t code | Designation |
|---|---|---|---|
| ECE 2215 | 2017 | T1 | Head |
| ECE 4127 | 2016 | T2 | Professor |
| ECE 1203 | 2019 | T3 | Lecturer |
| ECE 2219 | 2017 | T2 | Professor |
Explanation: All t code values in Courses (T1, T2, T3) exist in Teacher. No NULL padding is needed. The result matches the Natural Join.
Preserves all rows from the right table (Teacher). Unmatched rows get NULL in Courses columns.
Relational algebra:
Courses⟖TeacherMySQL query:
SELECT Courses.Code, Courses.Series, Teacher.`t code`, Teacher.Designation
FROM Courses
RIGHT JOIN Teacher ON Courses.`t code` = Teacher.`t code`;
Outcome Table (5 rows):
| Code | Series | t code | Designation |
|---|---|---|---|
| ECE 2215 | 2017 | T1 | Head |
| ECE 4127 | 2016 | T2 | Professor |
| ECE 2219 | 2017 | T2 | Professor |
| ECE 1203 | 2019 | T3 | Lecturer |
NULL | NULL | T4 | Lecturer |
Explanation: Teacher T4 has no matching course. It appears with NULL for Code and Series.
Retains all rows from both tables. Missing attributes from either side are padded with NULL.
Relational algebra:
Courses⟗TeacherMySQL query:
SELECT Courses.Code, Courses.Series, Courses.`t code`, Teacher.Designation
FROM Courses
LEFT JOIN Teacher ON Courses.`t code` = Teacher.`t code`
UNION
SELECT Courses.Code, Courses.Series, Teacher.`t code`, Teacher.Designation
FROM Courses
RIGHT JOIN Teacher ON Courses.`t code` = Teacher.`t code`;
Outcome Table (5 rows):
| Code | Series | t code | Designation |
|---|---|---|---|
| ECE 2215 | 2017 | T1 | Head |
| ECE 4127 | 2016 | T2 | Professor |
| ECE 2219 | 2017 | T2 | Professor |
| ECE 1203 | 2019 | T3 | Lecturer |
NULL | NULL | T4 | Lecturer |
Explanation: Combines all matching rows plus unmatched teacher T4 with NULL values.
Topic: T02.2 · Attribute types · Section B
Question.
Differentiate between-
(i) Simple and composite attribute
(ii) Single-valued and multi-valued attribute
Answer.
(i) Simple vs Composite Attribute:
| Feature | Simple (Atomic) Attribute | Composite Attribute |
|---|---|---|
| Definition | Cannot be divided into smaller subparts. | Can be divided into smaller subparts that form independent attributes. |
| Structure | Holds a single atomic value from its domain. | Forms a hierarchy of component attributes. |
| E-R Notation | Single ellipse connected to the entity rectangle. | An ellipse connected to component ellipses. |
| Storage / Schema | Maps to a single column in a relational table. | Flattened into separate columns for each subpart. |
| Example | salary, student_id, credits | name (first_name, last_name), address (street, city, zip_code) |
(ii) Single-Valued vs Multi-Valued Attribute:
| Feature | Single-Valued Attribute | Multi-Valued Attribute |
|---|---|---|
| Definition | Holds at most one value for a specific entity instance. | Can hold a set of values for a single entity instance. |
| Values per Entity | Exactly one value per record. | Zero, one, or multiple values per record. |
| E-R Notation | Single ellipse. | Double ellipse (concentric ellipses). |
| Table Conversion | Stored directly in the main entity table. | Converted into a separate table with the entity primary key. |
| Example | date_of_birth, roll_no, nid | phone_numbers, degrees, email_addresses |
Topic: T09.3 · Transaction states / life-cycle diagram · Section B
Question. What is a transaction? Describe the life cycle of a transaction.
Answer.
Definition:
A transaction is a logical unit of program execution that accesses and possibly updates various data items in a database.
Life Cycle of a Transaction:
A transaction moves through five distinct states during its execution:
Figure: Transaction State Transition Diagram (Source: Deck 07, Slide 8)
Topic: T10.2 · Conflict equivalence by swapping (proof) · Section B
Question. Draw a concurrent schedule equivalent to serial schedule. Prove its step by step swapping process.
Answer.
Consider two transactions T1 and T2 executing on accounts A and B:
Below is a concurrent (interleaved) schedule S that is equivalent to the serial schedule ⟨T1,T2⟩:
| Step | T1 | T2 |
|---|---|---|
| 1 | read(A) | |
| 2 | write(A) | |
| 3 | read(A) | |
| 4 | write(A) | |
| 5 | read(B) | |
| 6 | write(B) | |
| 7 | read(B) | |
| 8 | write(B) |
Two consecutive instructions can be swapped if they belong to different transactions and do not conflict. Instructions on different data items (A and B) never conflict. We transform S into serial schedule ⟨T1,T2⟩ through 4 swaps:
Resulting schedule:
| Step | T1 | T2 |
|---|---|---|
| 1 | read(A) | |
| 2 | write(A) | |
| 3 | read(B) | |
| 4 | write(B) | |
| 5 | read(A) | |
| 6 | write(A) | |
| 7 | read(B) | |
| 8 | write(B) |
All operations of T1 now precede all operations of T2. This is exactly the serial schedule ⟨T1,T2⟩.
Result: Since S was transformed into serial schedule ⟨T1,T2⟩ using only valid swaps of non-conflicting adjacent instructions, S is conflict equivalent to ⟨T1,T2⟩ and is conflict serializable.
Topic: T10.3 · Precedence-graph test → cycle → serial order(s) · Section B
Question.
Which of the following schedule is (conflict) serializable? For each serializable schedule, determine the equivalent serial schedules.
(i) r1(X);r3(X);w1(X);r2(X);w3(X)
(ii) r1(X);r3(X);w3(X);w1(X);r2(X)
Answer.
Both schedules operate on a single data item X across transactions T1,T2,T3.
We identify every conflicting instruction pair in time order:
Edges in the precedence graph: {T1→T3,T3→T1,T1→T2,T2→T3}.

Verdict for (i): Schedule (i) contains cycles. It is NOT conflict serializable. No equivalent serial schedule exists.
We identify every conflicting instruction pair in time order:
Edges in the precedence graph: {T1→T3,T3→T1,T3→T2,T1→T2}.

Verdict for (ii): Schedule (ii) contains a cycle. It is NOT conflict serializable. No equivalent serial schedule exists.
Conclusion: Neither schedule is conflict serializable.
Topic: T10.5 · View serializability (3 conditions, blind writes) · Section B
Question.
What is view serializability? Why do we need view serializability? Check the view serializability of the following schedule if any.
| T1 | T2 |
|---|---|
| R(X) | |
| W(X) | |
| R(X) | |
| W(X) | |
| R(Y) | |
| W(Y) | |
| R(Y) | |
| W(Y) |
Answer.
A schedule S is view serializable if it is view equivalent to some serial schedule. Two schedules S and S′ with the same set of transactions are view equivalent if three conditions are satisfied for every data item Q:
Let the given schedule be S:
| Step | T1 | T2 |
|---|---|---|
| 1 | R(X) | |
| 2 | W(X) | |
| 3 | R(X) | |
| 4 | W(X) | |
| 5 | R(Y) | |
| 6 | W(Y) | |
| 7 | R(Y) | |
| 8 | W(Y) |
We check if S is view equivalent to the serial schedule S′=⟨T1,T2⟩:

All three conditions are satisfied with respect to the serial schedule ⟨T1,T2⟩. (Also, every conflict edge goes T1→T2, so the schedule is also conflict serializable).
Result: The schedule is view serializable, equivalent to the serial schedule:
⟨T1,T2⟩Topic: T11.4 · Deadlock: conditions, prevention vs detection, wait-for graph, victim selection · Section B
Question. What is deadlock? Describe the time-shared locking protocol with example.
Answer.
Assumption: "Time-shared locking protocol" is an exam misprint for the Two-Phase Locking (2PL) protocol.
Deadlock:
A deadlock is a situation where two or more transactions are in a mutual wait condition, each waiting for a data lock held by the other. Neither transaction can make progress.
Two-Phase Locking (2PL) Protocol:
The Two-Phase Locking protocol ensures conflict serializability by requiring that each transaction acquires and releases locks in two distinct phases:
Lock Point:
The point where a transaction acquires its final lock is its lock point. Serializability is guaranteed in the order of transaction lock points.

Figure: Two-Phase Locking Protocol (Source: Deck 08, Slide 13)
Example:
Consider transaction T1 modifying accounts A and B:
| Step | Action | Phase |
|---|---|---|
| 1 | lock-S(A); read(A) | Growing |
| 2 | lock-X(B); read(B); write(B) | Growing (Lock Point) |
| 3 | unlock(A) | Shrinking begins |
| 4 | unlock(B) | Shrinking |
T1 obtains all locks before releasing any lock. This satisfies 2PL and guarantees serializability.
Topic: T05.7 · Multi-table business-schema query sets (MySQL): Covid, Company, Insurance, E-commerce · Section B
Question.
Define RDMS. Consider the following insurance database where the primary keys are underlined.
Person(driver_id, name, address)
Car(license, model, year)
Accident(report_no, date, location)
Owner(driver_id, license)
Participated(driver_id, report_no, car, damage_amount)
Write MySQL for the following queries-
(i) Find the number of accidents in which the cars belonging to "John Smith" were involved.
(ii) Add a new accident to the database, assuming any values for required attributes.
(iii) Update the car "Mazda" belonging to "John".
(iv) Update the damage amounts $3000 for the car with license number "YJK-100" in the accident with report number "APR2197".
(Note: Printed as "RDMS" in original question paper; refers to "RDBMS")
Answer.
Definition of RDBMS: An RDBMS (Relational Database Management System) is a database management software based on the relational model of data. It stores information in tables (relations) of rows and columns, enforces data integrity using keys and constraints, and provides a structured declarative query language (SQL) for retrieval and manipulation.
(i) Number of accidents involving cars owned by "John Smith":
SELECT COUNT(DISTINCT p.report_no) AS accident_count
FROM Participated p
JOIN Owner o ON p.car = o.license
JOIN Person per ON o.driver_id = per.driver_id
WHERE per.name = 'John Smith';
(ii) Add a new accident with sample values:
INSERT INTO Accident (report_no, date, location)
VALUES ('AR-2024-01', '2024-10-15', 'Dhaka-Rajshahi Highway');
(iii) Update the car "Mazda" belonging to "John":
Assumption: The query updates the manufacturing year of John's Mazda to 2022.
UPDATE Car c
JOIN Owner o ON c.license = o.license
JOIN Person p ON o.driver_id = p.driver_id
SET c.year = 2022
WHERE p.name = 'John'
AND c.model = 'Mazda';
(Alternative standard SQL subquery:
UPDATE Car
SET year = 2022
WHERE model = 'Mazda'
AND license IN (
SELECT o.license
FROM Owner o
JOIN Person p ON o.driver_id = p.driver_id
WHERE p.name = 'John'
);
)
(iv) Update damage amount to $3,000 for car "YJK-100" in accident "APR2197":
UPDATE Participated
SET damage_amount = 3000
WHERE car = 'YJK-100'
AND report_no = 'APR2197';
Variant for 2024 Q.5(b) (6 marks): The same RDBMS definition and four queries directly solve the question.
Topic: T07.1 · What a trigger is, its purposes, and its syntax · Section B (Repeated question: Also asked in 2018 | Solved in T07)
Question. What is triggering? What are the purposes of using triggering? Write the syntax for creating a trigger.
Answer.
A trigger is a stored SQL block. The DBMS executes it automatically when a modification occurs on a table or view.
The automatic detection of the event and execution of the trigger action is called triggering.
Triggers follow the ECA (Event-Condition-Action) model:
INSERT, UPDATE, or DELETE) that activates the trigger.CHECK, FOREIGN KEY) cannot express.General Template:
DELIMITER //
CREATE TRIGGER trigger_name
{BEFORE | AFTER} {INSERT | UPDATE | DELETE}
ON table_name
FOR EACH ROW
BEGIN
-- Trigger body statements
-- Access row values via OLD.column_name and NEW.column_name
-- Terminate and rollback on error using SIGNAL
END //
DELIMITER ;
BEFORE | AFTER: Specifies whether the action executes before modifying table data or after the modification completes.INSERT | UPDATE | DELETE: Identifies the DML event that activates the trigger.ON table_name: Specifies the target table.FOR EACH ROW: Defines a row-level trigger that runs once for each affected row.OLD and NEW: Transition qualifiers that refer to column values before and after the change.Example (Enforcing non-negative stock before insert):
DELIMITER //
CREATE TRIGGER trg_check_product_stock
BEFORE INSERT ON Products
FOR EACH ROW
BEGIN
IF NEW.stock < 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Error: Stock level cannot be negative';
END IF;
END //
DELIMITER ;
Variant for 2020 Q.8(a) (4 marks): The same definition, purposes, syntax template, and example answer the question directly.
Topic: T08.8 · Normalize an unnormalized table → 1NF → 2NF → 3NF · Section B
Question.
Consider the given structure below:
| Proj. Num. | Proj. Name | Emp. No. | Emp. Name | Job Class | Chg/Hr | Hrs. Biller. | Total Charge |
|---|---|---|---|---|---|---|---|
| 13 | Banking | 103 | John | Analyst | 500 | 8 | 4000 |
| 105 | Steve | Programmer | 300 | 8 | 2400 | ||
| 26 | Telecom | 115 | Jim | Business Analyst | 100 | 10 | 1000 |
| 717 | Joe | Engineer | 300 | 7 | 2100 | ||
| 39 | Finance | 113 | David | Team Leader | 1000 | 4 | 4000 |
| 120 | Jian | DBA | 800 | 3 | 2400 |
Proj. Num. and Proj. Name cells span both employee rows for each project)
Answer.
Proj. Name is repeated for every employee assigned to the same project.Total Charge is a derived attribute (Total Charge=Chg/Hr×Hrs. Biller.). Storing calculated values wastes space and creates data inconsistency risks.Chg/Hr) for a job class (e.g., "Programmer") changes, multiple rows across different projects must be updated. Missing a single row produces conflicting hourly rates.Emp. No. is part of the primary key and cannot be NULL.(Note: We use Hrs_Billed to denote the column printed as "Hrs. Biller.")
Identified Functional Dependencies:
Fill in the merged project cells so that each row represents an atomic, complete record:
| Proj_Num | Proj_Name | Emp_No | Emp_Name | Job_Class | Chg_Hr | Hrs_Billed |
|---|---|---|---|---|---|---|
| 13 | Banking | 103 | John | Analyst | 500 | 8 |
| 13 | Banking | 105 | Steve | Programmer | 300 | 8 |
| 26 | Telecom | 115 | Jim | Business Analyst | 100 | 10 |
| 26 | Telecom | 717 | Joe | Engineer | 300 | 7 |
| 39 | Finance | 113 | David | Team Leader | 1000 | 4 |
| 39 | Finance | 120 | Jian | DBA | 800 | 3 |
PK: (Proj_Num, Emp_No)
Remove partial dependencies on the composite key (Proj_Num, Emp_No):
Decomposed into three relations:
PROJECT(Proj_Num, Proj_Name) with PK Proj_NumEMPLOYEE_2NF(Emp_No, Emp_Name, Job_Class, Chg_Hr) with PK Emp_NoASSIGNMENT(Proj_Num, Emp_No, Hrs_Billed) with PK (Proj_Num, Emp_No)In EMPLOYEE_2NF, there is a transitive dependency:
We decompose EMPLOYEE_2NF into EMPLOYEE and JOB.
PROJECT
| Proj_Num | Proj_Name |
|---|---|
| 13 | Banking |
| 26 | Telecom |
| 39 | Finance |
PK: Proj_Num
JOB
| Job_Class | Chg_Hr |
|---|---|
| Analyst | 500 |
| Programmer | 300 |
| Business Analyst | 100 |
| Engineer | 300 |
| Team Leader | 1000 |
| DBA | 800 |
PK: Job_Class
EMPLOYEE
| Emp_No | Emp_Name | Job_Class |
|---|---|---|
| 103 | John | Analyst |
| 105 | Steve | Programmer |
| 115 | Jim | Business Analyst |
| 717 | Joe | Engineer |
| 113 | David | Team Leader |
| 120 | Jian | DBA |
PK: Emp_No | FK: Job_Class references JOB(Job_Class)
ASSIGNMENT
| Proj_Num | Emp_No | Hrs_Billed |
|---|---|---|
| 13 | 103 | 8 |
| 13 | 105 | 8 |
| 26 | 115 | 10 |
| 26 | 717 | 7 |
| 39 | 113 | 4 |
| 39 | 120 | 3 |
PK: (Proj_Num, Emp_No) | FKs: Proj_Num references PROJECT(Proj_Num), Emp_No references EMPLOYEE(Emp_No)
← Prev: 2019 | Explanation Layer | Original Question Paper | Next: 2021 →