Faculty Of Computer Studies M359 - Form A Relational databases: theory and practice Midterm Examination Marking Guide Spring – 2011-2012 Date ______ Number of Exam Pages: (10) Time Allowed: ( 2 ) Hours Instructions: 1. This exam consists of three parts: Part I: 5 obligatory Multiple Choice Questions (MCQ), each worth 2 marks for a total of 10 marks Part II: 6 short essay questions of which you can choose any 5. Each question is worth 8 marks for a total of 40 marks. Part III: 6 problems of which you can choose any 4. Each problem is worth 12.5 marks for a total of 50 marks. 2. Write all your answers in the answer booklet and not in this questions booklet. 3. Use of calculators or any other electronic devices is not permitted in this exam. Good Luck : هذا االمتحان مكون من ثالثة اجزاء.1 اسئلة اجبارية من نوع5 :الجزء االول االختيار المتعدد مخصص لكل سؤال درجتان درجات10 باجمالى اسئلة اختبارات قصيرة يختار6 :الجزء الثانى 8 منها و مخصص لكل سؤال5 الطالب اى درجة40 درجات بإجمالى 4 مسائل يختار الطالب اى6 :الجزء الثالث درجة12,5 منها و مخصص لكل سؤال درجة50 بإجمالى برجاء كتابة االجابات فى ورقة االجابة و.2 .ليس فى ورقة االسئلة ال يسمح باستخدام االلة الحاسبة او اى من.3 .االدوات االلكترونية فى هذا االمتحان حظ سعيد Part I: answer ALL of the following 5 Multiple Choice Questions (MCQ), each worth 2 marks for a total of 10 marks. 1. Referring to the three schema architecture, which schema describes how data is placed on the hard disk? a. External schema b. Storage schema c. Logical schema d. ER schema 2. What is the property of modern databases that allows the logical schema to be changed without having to modify the code of existing application programs? a. Physical data independence b. Robustness c. Logical data independence d. None of the above 3. What is the end product of the analysis phase of the database development life cycle? a. Relational database design b. Complete database implementation c. Conceptual Data Model (CDM) d. Requirements Specifications 4. Which of the following will be considered a valid relational table? a. a table that has duplicate tuples b. a table whose rows have multiple values in each field c. a table with multiple data types appearing in a single column d. a table with only a single field 5. Which of the following database properties is undesirable? a. Uncontrolled redundancy b. Lossy joins c. Lost dependencies d. All of the above Part II: Answer ANY 5 of the following 6 short essay questions. Each question is worth 8 marks for a total of 40 marks. 1. Explain 4 different means by which constrains are represented in the Conceptual Data Model (CDM). a. b. c. d. By specifying participation conditions By specifying the degree of relationship (1:1, 1:n, or n:m) By specifying entity unique identifiers By specifying additional constraints 2. Briefly explain the different options usually available when specifying the system action in response an attempted deletion of a referenced tuple that would result in violating of the referential integrity constraint. Restrict: Disallow the deletion. Cascade: propagate the deletion by deleting all referring tuples. Default: perform the deletion and apply a predefined default value in place of the deleted value in the referring tuples. 3. Briefly explain the main drawbacks of the client-multi-server approach of distributed database management a. The user must manage the connections to remote servers b. The user must be aware of where the data is located, thus losing the desirable property of location transparency 4. A Mother-child relation is naturally 1:m. Briefly explain what is wrong with the following database design for this relationship? Mother Living -Child Mother-ID Child-ID Mother-Name Child-ID Child-Name 1 1 1 2 3 1 2 3 4 5 Alia Laila Sarah Kawthar Mariam 1 2 3 4 5 Fahd Sally Ramy Lamis Wagdy The problem is that the relation Mother is un-normalized (not in 2NF) because Mother-Name will not be dependent on the whole primary key, rather it will be dependent on only part of the primary key (Mother-ID). This will result in possible insertion, deletion and update anomalies. 5. Explain three important advantages of SQL routines. SQL routines provide the following advantages: a. Security: only execute privileges can be given to users, without any other explicit privileges. This enhances security. b. Efficiency: SQL routines can be stored on the server side, thus resulting in lower network traffic c. The separation of concerns: developers will spate the internal details of how a certain procedure is implemented from the way it is used. 6. Briefly explain what is meant by a lost dependency (also called a hidden dependency), and how this problem can be corrected. A lost dependency is a situation that arises due to the incompatibility of normalization and the preservation of all functional dependencies in the ER diagram. It results in not being able to directly represent some functional dependencies in the ER diagram, thus losing part of the problem specifications. This problem can be corrected by specifying constraints in the additional constraints section to restore the lost dependencies. Part III: Answer ANY 4 of the following 6 problems. Each problem is worth 12.5 marks for a total of 50 marks. 1. Develop a Conceptual Data Model (CDM) for a student advising database, including the ER diagram, entity types, additional constraints and assumptions (limitations are not needed). Each student has a unique ID, a name, a telephone and an address, and must be assigned to exactly one tutor as an advisor. Not every tutor is an advisor, but a tutor may advise many students. A student has taken zero or more courses in the past, for which we need to record the year and semester, in which the course was taken, and the grade achieved. Courses have unique IDs and we need to keep information about the course ID, name and description. E-R Diagram: Tutor Student StudentCourse Course Entity Types: Tutor(TID, TName) Student (SID, SName, Tel, Address) Student-Course (TID, SID, Year, Semester, Grade) Course (CID, CName, Description) Additional Constraints: c.1 Student-Course is a weak entity type dependent on Student. Matching entities must have matching values of SID. c.2 Student-Course is a weak entity type dependent on Course. Matching entities must have matching values of CID. Assumptions: (Students may make different assumptions, but their assumptions must match their diagrams): a.1 A course may be stored in the database which has never been offered before. 2. Give an E-R diagram to represent the following occurrence diagram, assuming that the diagram is representative of the application constraints. E1 Role A Role B Role A Role A Role B Role B A: Role B Role A E1 3. Convert the following conceptual model into a relational representations R C Entity types: C(c1, c2) D(d1, d2) D relation C c1: c1domain c2: c2domain primary key: c1 relation R c1: c1domain d1d1domain primary key a1, b1 foreign key c1 references C foreign key d1 references D constraint (project C over c1) difference (project R over c1)) is empty constraint (project D over d1) difference (project R over d1)) is empty relation D d1: d1domain d2: d2domain primary key d2 4. for the following Employee database, write each of the following queries in relational algebra: Worker (ID, WName, HourlyRate, CID) Employee (EID, EName, Salary, CID) Company (CID, CName) Where ID is a unique ID over the set of all workers and all employees. a. Get the names of all employees with a salary > 2000 project (select employee where Salary > 2000) over EName b. Get the names of all employees, along with the name of the company in which they work project (Employee join Company) over EName, CName c. Get the names of all employees who are also employed as workers. project (workers intersect Employees) over WName 5. For each of the following relations and functional dependencies, determine: 1. All candidate keys 2. The highest normal form to which the relation conforms 3. The reasons why it conforms to the normal form identified in 2. above and does not comply with the next higher normal form (if applicable) 4. A normalization of the relation into the next higher normal form (if applicable) Books (BookID, ISBN, BookTitle, Author) FDs: FD1: BookID ISBN, BookTitle, Author FD2: ISBN BookID, BookTitle, Author 1. Candidate key 1: BookID Candidate key 2: ISBN 2. BCNF 3. It is in BCNF because every non-trivial determinant is a candidate key. 4. Not applicable 6. For the same worker-employee-company database of question 4, write the following SQL queries: Worker (ID, WName, HourlyRate, CID) Employee (EID, EName, Salary, CID) Company (CID, CName) Where ID is a unique ID over the set of all workers and all employees. a) Write a SQL query to retrieve the names of all workers whose Hourly-Rate is above 20. select WName from Worker where HourlyRate > 20 b) Write a SQL query to retrieve the names of all companies and the number of employees employed by each company. select CName, Count(*) from Employee inner join Company on Employee.CID = Company.CID group by CName c) Write a SQL query to retrieve for each company, the name of the company and the name(s) of the top paid employee(s) in that company. select CName, EName from Employee E1 inner join Company on E1.CID = company.CID where Salary = (select Max(Salary) from Employee E2 where E1.CID = E2.CID) Reference Sheet Properties of Functional Dependencies: Property 1: combining functional dependencies If A ↦ B and A ↦ C, then A ↦ B, C Property 2: extending determinants If A ↦ C and A is a subset of B, then B ↦ C Property 3: transitivity If A ↦ B and B ↦ C then A ↦ C Property 4: augmentation If A ↦ B, then A, C ↦ B, C Normal Forms: 1NF: A relation is in first normal form (1NF) if and only if it has no duplicate tuples and in each tuple, each value of every attribute is a single value. 2NF: A relation is in second normal form (2NF) if and only if every non-primary key attribute is fully functionally dependent on the primary key. 3NF: A relation is in third normal form (3NF) if and only if it is in 2NF and no nonprimary key attribute is transitively dependent on the primary key. Definition: An attribute A is transitively dependent (TD) on a set of attributes X in a relation R if there is a set of attributes Y such that all the following properties hold: TD(i) X ↦ Y and Y ↦ A. TD(ii) It is not true that Y ↦ X. TD(iii) A is not an attribute of either X or Y. We included TD(ii) to rule out the situation where Y is an alternate key. BCNF: A relation is in Boyce–Codd normal form (BCNF) if and only if each irreducible determinant of a non-trivial FD is a candidate key. Definitions: A determinant A in A ↦ B is irreducible if there is no proper subset S of A such that S ↦ B A trivial FD is one in which the right hand side is a subset of the left hand side Definition: Weak Entity type: Weak entity types are those entity types that 1. Have a mandatory relationship with another entity type where 2. The identifier of that entity type is the same as, or a subset of, the weak entity type, and 3. That entity type is at the :1 end of this relationship. General forms of relational algebra expressions: select: select <relation> where <selection condition> project: project <relation> over <attribute list> combining select and project: project (select <relation> where <selection condition>) over <attribute list> alias: <alias name> alias (<relational algebra expression>) join: <relation1> join <relation2> rename: <relation> rename (<old attribute1 name> as <new attribute1 name>, <old attribute2 name> as <new attribute2 name>, ... ) join with renaming: <relation> join (<relation> rename (<old attribute1 name> as <new attribute1 name>, <old attribute2 name> as <new attribute2 name>, ... )) divide: divide <relation1> by <relation2> union: <relation1> union <relation2> intersection: <relation1> intersection <relation2> difference: <relation1> difference <relation2> times: <relation1> times <relation2> general constraint: constraint <condition>
© Copyright 2025 Paperzz