ICS 324 – 03 (081) Final Exam 1 of 10 King Fahd University of Petroleum and Minerals College of Computer Sciences and Engineering Department of Information and Computer Science First Semester 2008 - 2009 (081) ICS 324 Database Systems Section 03 Final Exam Solution Weight: 25 % Maximum Points: 100 Time: 07:00 – 09:00 pm Place: 24 - 120 Student #: ______________ Student Name: ________________________________ Problem Problem Problem Problem Problem Problem Problem 1 2 3 4 5 6 7 30 15 10 15 10 10 10 TOTAL 100 NOTES: To make your answers more meaningful, write your assumptions, if any, as part of your answers. Use the time to write the answers only for what is required in the problem. Don’t waste time in writing which is not required 04 February 2009 ICS 324 – 03 (081) Final Exam 2 of 10 Problem 1 [30 points] Answer all the following short questions. Each question is for 2 points. 1.1 Define the term “data” as precisely as you can. Data are the known facts that can be recorded and have an implicit meaning. 1.2 What is the difference between “data” and “information” Information is the processed and unambiguously interpretable form/representation of data. 1.3 What is the difference between “database system” and “database” Database is a collection of related data whereas a database System is the DBMS software, the database, and the software programs that are executed to transform the data from the database to information. 1.4 1.5 What is meta-data? Give an example. Meta-data is the DBMS catalog that stores the description of a particular database. It includes the table names, attribute names, , types, and constraints. What is program-data independence? program-data independence is the insulation between programs and data that allows changes in data structures and storage organization without having to change the DBMS access programs. ICS 324 – 03 (081) 1.6 Final Exam 3 of 10 List four tasks (responsibilities) of a database administrator. DBA is responsible for Authorizing access to the database Coordinating and monitoring its use Acquiring software and hardware resources Controlling its use Monitoring efficiency of operations. 1.7 Define data redundancy. You can support your answer with an example. Data redundancy is storing a data item more than once in the same database. For example, name of student may appear in transcript record, registration notice record. Etc. 1.8 Data redundancy leads to many problems. Describe one such problem. Keeping the redundant data consistent is an important issue. It may be updated in one place but not in others. 1.9 Illustrate data integrity with a simple example. A student number at KFUPM must be unique. Now whenever a new student number is inserted into the database it must be checked by the DBMS to be unique as a part of the insert operation. 1.10 A data model is a collection of concepts that can be used to describe the structure of a database. Just list four concepts that are used to describe the data in relational data model. Data modeling concepts in relational data model are Attribute Domain Relation Primary key Foreign key ICS 324 – 03 (081) Final Exam 4 of 10 1.11 A database should always be in a valid state. What does this mean? A valid state of a database implies that each data value in the database satisfies the relevant integrity constraints. 1.12 Illustrate the difference between a relation schema and relation state with a simple example. R(A, B, C) is a relation schema and { <a1, b1, c1>, <a2, b2, c2>} is a relation state. 1.13 Describe the mathematical statement r(R) dom(A1) x dom(A2) x dom(A3) in words. Relation state r of a relation R is a subset of the cartesian product of domains of A1, A2, and A3. 1.14 List two characteristics of relation in relational data model. All values are considered atomic (indivisible). Each value in a tuple must be from the domain of the attribute for that column Attributes in a relation schema R (and of values within each tuple) are ordered The tuples are not considered to be ordered, even though they appear to be in the tabular form. 1.15 Two main relational model constraints are domain constraints and key constraints. In a create table statement an attribute is defined as Dno INT NOT NULL, Describe the domain constraints of attribute Dno as specified in the statement. The domain constraint of Dno has been specified by the type INT which implies that all integer numbers from - to + are the valid values for the attribute Dno. Of course in computer storage is limited by the maximum value that can be stored in the assigned space (1 byte, 2 byte, or 4 bytes) for integer numbers. However the value cannot be NULL. ICS 324 – 03 (081) Final Exam 5 of 10 Problem 2 [15 points] (Functional Dependencies and Normalization) (a) [3+2 points] Define second normal form (2NF) and illustrate with an example. (b) [10 points] Consider the following relation schema and the functional dependencies: CAR-SALE (Car#, Date-sold, Salesman#, Commission, Discount) Primary key: Car#, Salesman# Functional dependencies: (fd1) Salesman# → Commission (fd2) Date-sold → Discount (b-1) [2 points] Is the given relation schema in 1NF? Explain your answer. (b-2) [2 points] Is the given relation schema in 2NF? Explain your answer. (b-3) [2 points] Is the given relation schema in 3NF? Explain your answer. (b-4) [4 points] If in your opinion the given relation schema is not in 3NF then transform it into a set of relation schemas such that each resulting relation schema is in 3NF. Solution (a) A relation schema R is in second normal form (2NF) if every non-prime attribute A in R is fully functionally dependent on the primary key (b) (b-1) The given relation schema is in 1NF because every attribute is atomic. (b-2) The given relation schema is not in 2NF because Salesman# → Commission defines that Commission is functionally dependent on Salesman# which is part of the primary key. (b-3) The given relation schema is not in 3NF because it is not in 2NF (b-4) CAR-SALE (Car#, Date-sold, Salesman#, Commission, Discount) Dividing the relation schema into two relations CAR-SALE-1 (Car#, Date-sold, Salesman#, Discount) CAR-SALE-2(Salesman#, Commission) CAR-Sale-1 is not in 3NF due to transitivity; Car# → Date-sold and Date-sold → Discount. Therefore subdividing the CAR-SALE-1 into two relations gives the following relation schemas where each relation is in 3NF. CAR-SALE-1-A (Car#, Date-sold, Salesman#) CAR-SALE-1-B (Date-sold, Discount) CAR-SALE-2(Salesman#, Commission) ICS 324 – 03 (081) Final Exam 6 of 10 Problem 3 [10 points] (Practical Database Design Methodology) (a) [4 points] In your understanding, what is the relationship between an information system and a database system? (b) [6 points] What are the six phases of database design? Describe each phase briefly. SOLUTION (a) A database system provides raw data for an information system (b) ICS 324 – 03 (081) Final Exam 7 of 10 Problem 4 [15 points] (Index Structures for Files and Physical Database Design) (a) [5 points] What are the differences between primary indexes and clustering indexes? (b) [5 points] Why can we have at most one primary index or clustering index on a file, but several secondary indexes? (c) [5 points] Creating an index on a relation attribute can improve its access but at the same time introduces an overhead to maintain the index. Under what circumstances the overhead is justified. Explain. ICS 324 – 03 (081) Final Exam 8 of 10 Problem 5 [10 points] (Query Processing) (a) [4 points] Describe or draw a diagram to show the typical steps involved in processing a query written in a high-level language like SQL. (b) [6 points] Translate the following SQL query into an equivalent relational algebra expression and then represent as a query tree. SELECT FNAME, LNAME, ADDRESS FROM EMPLOYEE WHERE DNO IN ( SELECT DNUMBER FROM DEPARTMENT WHERE DNAME='Research' ); ICS 324 – 03 (081) Final Exam 9 of 10 Problem 6 [10 points] (Transaction Processing Concepts) (a) [5 points] Illustrate the temporary update problem with an example. (Please note that a simple diagram without an appropriate explanation is not a sufficient answer) (b) [5 points] The desirable properties of a transaction are atomicity, consistency preservation, isolation, and durability. Explain what atomicity and isolation mean. ICS 324 – 03 (081) Final Exam 10 of 10 Problem 7 [10 points] (Concurrency Control Techniques) (a) [4 points] what is a lock? What is the basic two-phase locking (2PL) protocol? (b) [6 points] Below find a schedule S of two transaction T1 and T2 that exhibit the lost-update problem. Use locking and the 2PL to rewrite the schedule S as another schedule S’ that does not have this problem. Verify your answer by filling the column balx in the two schedules S and S’. S’ S Time t1 T1 T2 begin_transaction balx 550 Time t1 T1 T2 begin_transaction balx 550 t2 begin_transaction read (balx) 550 t2 begin_transaction write_lock (balx) 550 t3 read (balx) balx = balx + 100 550 t3 write_lock (balx) read (balx) 550 t4 balx = balx - 50 write (balx) 650 t4 wait balx = balx + 100 550 t5 write (balx) committ 500 t5 wait write (balx) 650 t6 committ 500 t6 wait Committ/ unlock (balx) 650 t7 read (balx) 650 t8 balx = balx - 50 650 t9 write (balx) 600 t10 Committ/ unlock (balx) 600