Blog
Database Systems MSc IT 3rd Term Past Paper 2019 UOS
University of Sargodha M.Sc. IT 3rd term Database Systems (CMP-3440) past paper 2019, retyped from the original paper, with solved answers below.
Solved answers
Q1 – Short questions
(i) Disadvantages of file processing systems: data redundancy (duplicate data in many files) causing inconsistency; program–data dependence; limited data sharing; lengthy development times; excessive program maintenance.
(ii) Disadvantage of normalization: it splits data into many tables, so queries need more joins, which can slow retrieval; the design also becomes more complex (sometimes tables are denormalised for performance).
(iii) Associative entity: an entity type that associates instances of other entity types and has its own attributes, e.g. ENROLLMENT (Grade, Date) linking STUDENT and COURSE, or ORDER LINE (Quantity) linking ORDER and PRODUCT: STUDENT —< ENROLLMENT >— COURSE.
(iv) Derived attribute: an attribute whose value can be calculated from other stored attributes, shown with a dashed oval or [ ]; e.g. Age derived from DateOfBirth, or Years Employed from Date Hired.
(v) Components of the database environment: CASE tools, repository, DBMS, database, application programs, user interface, data/database administrators, system developers and end users (any two).
(vi) Program–data dependence: in file processing, file descriptions are stored inside each application program, so any change to a file’s structure requires changing all programs that use it.
(vii) Total specialization rule: every instance of the supertype must also be a member of some subtype; shown by a double line from the supertype to the circle.
(viii) Self join: a join of a table with itself, using table aliases, to relate rows in the same table — e.g. listing employees with their managers from an EMPLOYEE table that has a ManagerID column.
(ix) Logical vs physical schema: the logical schema represents the data in terms of a data model (e.g. relations, attributes, keys) independent of storage; the physical schema describes how the data is actually stored — files, indexes, partitions, data types and access paths.
(x) Partial functional dependency: a dependency in which a non-key attribute depends on only part of a composite primary key, e.g. in (StudentID, CourseID) → Grade, if CourseID → CourseTitle. Its removal gives 2NF.
(xi) Unary one-to-many relationship: EMPLOYEE —Manages— EMPLOYEE, where one employee (manager) manages many employees and each employee has at most one manager.
(xii) Table vs view: a table (base table) physically stores data. A view is a virtual table defined by a query on one or more tables; it stores no data itself and is computed when used. Views simplify queries and restrict access.
(xiii) Consequences of anomalies: insertion anomaly (cannot add data without unrelated data), deletion anomaly (deleting a row loses other facts), and update/modification anomaly (the same fact must be changed in many rows, causing inconsistency).
(xiv) Referential integrity: a rule that every foreign-key value must either match an existing primary-key value in the referenced table or be null.
(xv) Table vs relation: a relation is a named two-dimensional table with special properties: every cell atomic, unique rows (no duplicates), unique column names, and the order of rows and columns does not matter. Not every table is a relation.
(xvi) DROP TABLE Student; (add CASCADE CONSTRAINTS in Oracle to remove dependent constraints).
Q2 – Advantages of the database approach
- Program–data independence: data descriptions are stored in the repository, so data can change without changing programs.
- Planned data redundancy: each fact is ideally stored once, reducing duplication.
- Improved data consistency: with less redundancy, updates are made in one place.
- Improved data sharing: many users and applications share one database through views.
- Increased productivity of application development: developers focus on functions rather than file handling; SQL and tools speed development.
- Enforcement of standards: naming, formats and access procedures are controlled by the DBA.
- Improved data quality: integrity constraints (keys, domains, referential integrity) reject invalid data.
- Improved data accessibility and responsiveness: ad-hoc queries with SQL without programming.
- Reduced program maintenance and improved decision support.
- Also: security (authorisation), backup and recovery, and concurrency control for many users.
Q3 – PRESCRIPTION to 3NF
Relation: PRESCRIPTION(PrescriptionID, Date, Medicine, Dosage, CustomerName, CustomerPhone, CustomerEmail). Primary key: PrescriptionID (each value is unique).
Functional dependencies:
- PrescriptionID → Date, Medicine, Dosage, CustomerName, CustomerPhone, CustomerEmail
- CustomerEmail → CustomerName, CustomerPhone (the e-mail identifies the customer; phone numbers are shared by different customers, e.g. 5755232233, so the phone cannot identify a customer)
The relation is in 2NF (single-attribute key) but not in 3NF because of the transitive dependency PrescriptionID → CustomerEmail → CustomerName, CustomerPhone. Customer data would be repeated for every prescription of the same customer.
3NF decomposition (adding a surrogate key for the customer):
- CUSTOMER(CustomerID, CustomerName, CustomerPhone, CustomerEmail)
- PRESCRIPTION(PrescriptionID, Date, Medicine, Dosage, CustomerID) — CustomerID is a foreign key to CUSTOMER.
(CustomerEmail can itself serve as the key of CUSTOMER if no CustomerID is wanted. If medicines have their own attributes, a MEDICINE(MedicineID, MedicineName) relation can also be created.) Both relations have no partial or transitive dependencies, so they are in 3NF.
Q4 – EER diagram
+--------------------------------------+
| PERSON |
| SSN (PK), Name, Address, City, |
| State, Zip, Telephone, |
| {Person Type} (Is Emp?, Is Vol?, |
| Is Donor?) - subtype discriminator |
+--------------------------------------+
| (single line = partial completeness)
(o) overlap rule
____________________|____________________
| | |
Is Emp? = "Y" | Is Vol? = "Y" | Is Donor? = "Y" |
+--------------+ +--------------+ +--------------+
| EMPLOYEE | | VOLUNTEER | | DONOR |
| Date Hired | | Skill | | |
+--------------+ +--------------+ +--------------+
| || (mandatory one)
< Donates >
| O< (one or many / zero or many)
+--------------+
| ITEM |
| Item ID (PK) |
| Description |
+--------------+- PERSON is the supertype with attributes SSN (identifier, underlined), Name, Address, City, State, Zip and Telephone.
- Partial completeness (single line) because a person need not be an employee, volunteer or donor.
- Overlap rule (o) because a person may belong to two or more subtypes at the same time.
- For overlapping subtypes the subtype discriminator is a composite attribute Person Type with Boolean components Is Employee?, Is Volunteer?, Is Donor? (each Y/N).
- EMPLOYEE has Date Hired; VOLUNTEER has Skill; DONOR has no attributes of its own but participates in Donates with ITEM.
- Cardinalities: a donor donates one or many items (mandatory many on the ITEM side); an item is donated by zero, one or many donors (optional many on the DONOR side) — a many-to-many relationship.
Q5 – Indexes
Purpose: an index is a table or data structure (usually a B-tree) used to determine the location of rows in a file that satisfy some condition. Indexes speed up retrieval for searching, sorting, joining and grouping without scanning the whole table, and can enforce uniqueness of keys. They cost extra storage and slow down inserts, updates and deletes because the index must also be maintained.
Rules for choosing attributes to index:
- Index the primary key of each table (unique index), and use indexes mostly on larger tables.
- Index search fields — columns frequently used in WHERE clauses.
- Index fields used in ORDER BY and GROUP BY clauses.
- Index foreign keys and other columns frequently used in joins.
- Index attributes with many distinct values; indexing columns with few values (e.g. gender) gives little benefit (bitmap indexes may be used instead).
- Avoid indexing columns that are updated frequently, and limit the number of indexes on tables with heavy insert/update activity.
- Check DBMS limits on the number of indexes per table; consider compressed keys for long values.
- Avoid indexing columns with many null values if the DBMS does not index nulls; avoid indexes on very small tables.
Q6 – SQL queries
-- a) students not enrolled in any course, ascending
SELECT StudentName
FROM STUDENT
WHERE StudentID NOT IN (SELECT StudentID FROM ENROLLMENT)
ORDER BY StudentName ASC;
-- b) courses with enrollment less than 15 (includes courses with 0 students)
SELECT C.CourseTitle
FROM COURSE C LEFT JOIN ENROLLMENT E ON C.CourseID = E.CourseID
GROUP BY C.CourseID, C.CourseTitle
HAVING COUNT(E.StudentID) < 15;
-- c) total number of students enrolled in Database Systems
SELECT COUNT(*) AS TotalEnrolled
FROM ENROLLMENT
WHERE CourseID = 3450;
-- d) titles of courses having exactly 3 credit hours
SELECT CourseTitle
FROM COURSE
WHERE CreditHours = 3;
