Database, Past Papers, UOS Main Campus

Database System Past Paper 2017 – BSSE 3rd Term UOS (CMP-3540)

ProgramBSSE
Term3rd
Year2017
Course codeCMP-3540
AnswersSolved ✓

University of Sargodha Database System (CMP-3540) paper for BS Software Engineering 3rd term, 2017 exam (80 marks, 2:30 hours). Solved answers are given below for all 16 short questions and all six long questions, including SQL queries tested in SQLite, the airline ER diagram converted to relations and CREATE TABLE commands with constraints.

Solved answers

Q1 – Short answers (16 × 2)

i. Anomaly: An undesirable side effect that occurs when data is changed in a badly designed (unnormalised) table, so that the data becomes inconsistent.

ii. Referential integrity constraint: A rule that every foreign key value must either be null or match an existing primary key value in the referenced table, e.g. ASSIGN.DeptNo must exist in DEPT.

iii. Anomalies in a database: Insertion anomaly – a fact cannot be stored without another unrelated fact; update anomaly – the same fact stored many times must be changed everywhere; deletion anomaly – deleting a row loses other useful facts. Normalisation removes them.

iv. Transitive dependency: A functional dependency A → C that holds because A → B and B → C, where B is not a key, e.g. StaffNo → DeptNo → DeptName. Removing it gives 3NF.

v. Hash index table: An index in which a hash function is applied to the key value to compute the address (bucket) of the record, giving very fast access for equality searches but not for range searches.

vi. Three-tier architecture: Client/server design with three layers: the client (user interface), the application/web server (business logic) and the database server (data storage).

vii. Logical vs physical data independence: Logical independence: the conceptual schema can change (e.g. add a column) without changing external views or programs. Physical independence: the internal schema (files, indexes, storage) can change without changing the conceptual schema.

viii. Integrity constraints: Rules that keep data valid and consistent, e.g. domain constraints, entity integrity (primary key not null and unique), referential integrity and business rules such as CHECK (Price > 0).

ix. Transaction: A logical unit of work containing one or more database operations that must be completed entirely or not at all, e.g. a funds transfer. Transactions follow the ACID properties.

x. Purpose of a data model: To describe the data, its relationships, constraints and meaning in a clear way, so that designers, programmers and users share one understanding before the database is built (e.g. the ER model).

xi. Aggregation: In the EER model, treating a relationship together with its participating entities as a higher-level entity, so that it can take part in another relationship.

xii. Degree vs cardinality of a relation: Degree is the number of attributes (columns); cardinality is the number of tuples (rows). A table with 4 columns and 10 rows has degree 4 and cardinality 10.

xiii. Subtype vs supertype: A supertype is a generic entity type (e.g. AIRCRAFT); subtypes are subgroups with their own extra attributes (FIXED WING, ROTARY WING) that inherit the supertype’s attributes and relationships.

xiv. Determinant: The attribute on the left side of a functional dependency. In StaffNo → Name, StaffNo is the determinant.

xv. Entity cluster: A virtual entity type used in an ERD to represent several entities and relationships as one, to simplify a large diagram.

xvi. Entity integrity vs referential integrity: Entity integrity: every primary key value is unique and not null. Referential integrity: every foreign key value is null or matches a primary key value in the related table.

Q2 – File processing and DBMS components

(a) Five disadvantages of file processing systems:

  1. Program–data dependence – programs depend on file formats.
  2. Duplication of data – the same data in many files wastes space and causes inconsistency.
  3. Limited data sharing – each application has its own private files.
  4. Lengthy development times – every new application needs file design and code from scratch.
  5. Excessive program maintenance – most of the IT budget goes on maintaining file programs.

(b) Nine major components of a database system environment:

  1. CASE tools – automated tools to design databases and applications.
  2. Repository – central store of metadata.
  3. DBMS – software to create, maintain and control access to the database.
  4. Database – the organised collection of related data.
  5. Application programs – programs that create and maintain data.
  6. User interface – languages, menus and screens for interacting with the system.
  7. Data and database administrators – people who manage data and the database.
  8. System developers – analysts and programmers who build applications.
  9. End users – people who add, delete and modify data and use the information.

Q3 – User views, conceptual schema and internal schema

LevelDescriptionExample
User views (external level)How different users see the part of the database they need; there can be many views, each hiding other dataA clerk sees only staff names and departments; payroll sees salaries
Conceptual schemaOne complete logical description of the whole database: entities, attributes, relationships and constraints, independent of storageSTAFF, ASSIGN, DEPT with keys and constraints
Internal schemaHow the data is physically stored: files, records, indexes, access paths and storage spaceSTAFF stored as a heap file with a B+ tree index on StaffNo

The three-schema (ANSI/SPARC) architecture separates these levels, which gives logical and physical data independence: the internal schema can change without affecting the conceptual schema, and the conceptual schema can change without affecting user views.

Q4 – SQL queries

Tables: STAFF(StaffNo, Name, Address, Gender), ASSIGN(StaffNo, DeptNo, Position), DEPT(DeptNo, Description, MaxNoStaff, MinNoStaff). The queries were tested in SQLite on sample data.

(a) Names of all staff:

SELECT Name
FROM STAFF;

(b) Departments that could have a staff count of 10 (10 lies between MinNoStaff and MaxNoStaff):

SELECT Description
FROM DEPT
WHERE MinNoStaff <= 10 AND MaxNoStaff >= 10;

(c) Total number of staff in each department (departments with no staff show 0):

SELECT d.DeptNo, d.Description, COUNT(a.StaffNo) AS TotalStaff
FROM DEPT d
LEFT JOIN ASSIGN a ON a.DeptNo = d.DeptNo
GROUP BY d.DeptNo, d.Description;

(d) Total number of staff already assigned to department(s), without sub-queries or GROUP BY. DISTINCT counts a staff member once even if assigned to several departments:

SELECT COUNT(DISTINCT StaffNo) AS AssignedStaff
FROM ASSIGN;

(e) Names of staff not yet assigned to any department:

SELECT s.Name
FROM STAFF s
LEFT JOIN ASSIGN a ON a.StaffNo = s.StaffNo
WHERE a.StaffNo IS NULL;

(f) Staff numbers of staff assigned to more than 3 departments:

SELECT StaffNo
FROM ASSIGN
GROUP BY StaffNo
HAVING COUNT(DeptNo) > 3;

Q5 – Little Hampton Air Company

(a) Entities: PILOT, AIRCRAFT (supertype) with subtypes FIXED WING AIRCRAFT and ROTARY WING AIRCRAFT, CREW CHIEF (an employee), and FLIGHT LOG (the hours a pilot flies an aircraft on a day, an associative entity between PILOT and AIRCRAFT).

EntityAttributes (PK underlined)
PILOTFlying_License_No, Pilot_Name
AIRCRAFTAircraft_No, Seating_Capacity, Aircraft_Type (subtype discriminator), Crew_Chief_ID (FK)
FIXED WINGAircraft_No (FK), Number_of_Engines
ROTARY WINGAircraft_No (FK), Blade_Speed
CREW CHIEFEmployee_ID, Name
FLIGHT LOGFlying_License_No, Aircraft_No, Flight_Date, Hours_Flown

(b) Relationships and cardinalities for the ER diagram:

  • PILOT flies AIRCRAFT – many-to-many (a pilot flies different aircraft on different days; an aircraft is flown by many pilots), resolved by FLIGHT LOG with Hours_Flown and Flight_Date.
  • PILOT qualified for AIRCRAFT TYPE – a pilot may be qualified for fixed wing, rotary wing or both (multivalued attribute or a QUALIFICATION entity).
  • CREW CHIEF maintains AIRCRAFT – one-to-many: each aircraft has exactly one crew chief; a crew chief may look after more than one aircraft.
  • AIRCRAFT is a supertype with total, disjoint specialisation into FIXED WING (Number_of_Engines) and ROTARY WING (Blade_Speed); Seating_Capacity is common to all.

Q6 – Converting the airline ER diagram to relations

Each strong entity becomes a relation, the multivalued attribute CheckPoint becomes its own relation, the 1:M relationships become foreign keys, and the recursive “Train by” relationship becomes a foreign key to PILOT.

  • AIRCRAFT (Aircraft_ID, Model, Capacity)
  • PILOT (Pilot_ID, Pilot_Name, Trainer_ID → PILOT.Pilot_ID) – “Train by”; null if the pilot was not trained in-house.
  • FLIGHTPATH (FlightPathId, FPDescription)
  • FLIGHTPATH_CHECKPOINT (FlightPathId → FLIGHTPATH, CheckPoint) – for the multivalued attribute CheckPoint.
  • SCHEDULE (Schedule_ID, Flight_Date, Flight_Time, Aircraft_ID → AIRCRAFT (Allocated), FlightPathId → FLIGHTPATH (Use), Pilot_ID → PILOT (Assigned Pilot))
  • SCHEDULE_CREW (Schedule_ID → SCHEDULE, Pilot_ID → PILOT, Role) – only if more than one pilot (e.g. co-pilot) can be assigned to a flight (Assigned).

The daily printout comes from: SELECT … FROM SCHEDULE … ORDER BY Flight_Date, Flight_Time;

Q7 – Hotel and Room tables

1. CREATE commands with integrity constraints:

CREATE TABLE Hotel (
  Hotel_No  CHAR(4)      PRIMARY KEY,
  Name      VARCHAR(40)  NOT NULL,
  Address   VARCHAR(80)  NOT NULL
);

CREATE TABLE Room (
  Room_No   SMALLINT     NOT NULL CHECK (Room_No BETWEEN 1 AND 500),
  Hotel_No  CHAR(4)      NOT NULL,
  Type      CHAR(1)      NOT NULL CHECK (Type IN ('S', 'D', 'F')),
  Price     DECIMAL(7,2) NOT NULL CHECK (Price > 0),
  PRIMARY KEY (Room_No, Hotel_No),
  FOREIGN KEY (Hotel_No) REFERENCES Hotel(Hotel_No)
);

2. Two rows in each table:

INSERT INTO Hotel VALUES ('H001', 'Pearl Inn',  'Club Road, Sargodha');
INSERT INTO Hotel VALUES ('H002', 'City Lodge', 'University Road, Sargodha');

INSERT INTO Room VALUES (101, 'H001', 'S', 3500.00);
INSERT INTO Room VALUES (201, 'H002', 'D', 5500.00);

3. Deleting a hotel row:

DELETE FROM Hotel WHERE Hotel_No = 'H001';

Room 101 still refers to H001, so the DBMS rejects the delete to protect referential integrity. The message is a foreign-key violation, for example Oracle: ORA-02292: integrity constraint violated – child record found; MySQL: Cannot delete or update a parent row: a foreign key constraint fails; SQLite: FOREIGN KEY constraint failed (tested). If the foreign key were declared with ON DELETE CASCADE, the hotel and its rooms would be deleted instead.

Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.