Lena Strömbäck, ankn 2324 2002-10-14 Written exam in the course TDDB 38 Database technology Date: 2002-10-19 Time: 8-12 Room: KÅRA, T1, T2, U1, U4 Equipment: English dictionary allowed Limits for passing: The exam consists of two parts: Part one requires 13 points for pass Part two requires 13 points for pass Grade 4 requires approx. 35 points Grade 5 requires approx. 45 points Results: Will be available within two weeks Teacher in charge: Lena Strömbäck, 0709-39 6776, 013-16 46 99, 013-282324 Almut Herzog Ross Lee Graham, 013-28 24 10 A Swedish version of the questions is found at the back of each sheet. Use one sheet for each question, even if you only write one line on it. This is necessary since several people correct the exam and we divide the assignments. For this same reason be sure to write your name and personal number on each page.
Part 1: Practical 1. ER/EER modelling (8p) While correcting database exams, the teachers come across the following (not so successful) attempt to create an ER/EER diagram. The diagram is supposed to model a company buying products from producers and selling to customers. Please give a careful explanation to all mistakes you find in the diagram and create a new, correct ER/EER diagram that is a better solution to the problem you think the student was trying to solve according to the figure below. EmpNum E-mail Works at Address Employee Office Manager EmpNum E-mail Phone Office Phone Department Department Producer ItemType1, Id, price ItemType2, Id, price ItemType3, Id, price Respons. for ItemType4, Id, price Customer ItemTypeN, Id, price Address List of all Items bought Buys a product
Del1: Praktisk 1. ER modellering 8p Vid rättning av databastentor hittade lärarna följande, inte helt lyckade, försök till ER/EERdiagram. Diagrammet är tänkt att modulera ett företag som köper produkter från en producent och sedan säljer dem vidare till kunder. Ge en grundlig förklaring till vilka misstag som finns i diagrammet och skapa ett nytt korrekt ER/EER diagram som är en bättre lösning till det problem som du tror studenten försökte lösa. EmpNum Works at Address EmpNum E-mail Employee Office Manager E-mail Phone Office Phone Department Producer ItemType1, Id, price ItemType2, Id, price Department Respons. for ItemType3, Id, price ItemType4, Id, price Customer ItemTypeN, Id, price Address List of all Items bought Buys a product
2. EER to relations (6p) This EER-diagram describes the mini-world of a riding school. There are people (e.g. employees), horseowners that own horses, and students that at certain dates participate in riding classes. Translate the EER-schema to a relational schema. Explain and motivate how the mapping is done. post code town street address telephone Person ID U o U birthdate number of owned horses Horseowner 1 Student n date owns participates birthdate n m name horse level name Riding Class start date Error!3. alization (4p) Given the following relation: Norm BOOKINGS(PassportNr,, Nationality, Flight, To, From, Date, Aircraft, #Passengers, MaxDistance) The three first attributes describes the passport number, name and nationality of a passenger. Flight is a flight on which this passenger is booked, To and From is the departure and destination on this flight. Date is the date of the booking. Aircraft is the type of aircraft to be used for this flight and the last two attributes describes the maximum number of passengers and the maximum distance for this aircraft type. Transform the relation so that it will be in BCNF, show every step you make and explain why you do it.
2. EER till relationer (6 p) Följande EER-diagram beskriver en mini-värld för en ridskola med hästar, hästägare och elever som tar ridlektioner. Översätt det till ett relationsschema. Förklara och motivera hur mappningen sker. post code town street address telephone Person ID U o U birthdate number of owned horses Horseowner 1 Student n date owns participates birthdate n m name horse level name Riding Class start date 3. Normalisering (5p) Betrakta följande relation: BOOKINGS(PassportNr,, Nationality, Flight, To, From, Date, Aircraft, #Passengers, MaxDistance) PassportNr, och Nationality beskriver passageraren. Flight är flightnumret som han/hon är bokad på. To och From beskriver avgångsort och destination för denna flight. Date är datumet som passageraren ska resa. Aircraft är flygplanstyp för flighten och de två sista attributen beskriver maximalt antal passangerare och maximal flygsträcka för denna flygplanstyp. Normalisera relationen till BCNF. Visa varje steg du gör och förklara varför du gör det.
4. SQL-queries (7p) The following is a snapshot from a database of a cargo company. The company employs drivers that use trucks to transport merchandise between two locations. Table name: Driver DriverID DriverLast DriverFirst 1001 Anderson Kim 1002 Smith D.J. 1003 Jones Jaime Table name: Truck TruckID TruckPlate TruckMaxCubicmeter 888 RFG 234 40 889 THA 399 55 890 UNN 002 48 Table name: Travel DriverID TruckID TravelStart TravelCubicmeter TravelDistance 1001 888 2002-08-02 08:00 40 200 1001 888 2002-08-02 12:00 20 210 1002 888 2002-08-03 07:11 40 60 1002 888 2002-08-03 09:20 30 100 1002 888 2002-08-03 14:15 0 80 1003 889 2002-08-03 06:45 50 148 1002 890 2002-08-03 07:00 46 500 a. Show all driver names in alphabetical order. (1p) Result: Andersson Kim Jones Jaime Smith D.J. b. List the driver names and their total number of travels. (1p) Result: Andersson 2 Smith 4 Jones 1 c. List license numbers and their total amount of transported cubic meters as well as the total of kilometres travelled (2p) Result: RFG 234 130 650 THA 399 50 148 UNN 002 46 500 d. How many kilometres did the trucks travel with a load of less than 80% of their maximum load? (No need to list non-matching trucks) (3p) Result: RFG 234 390
4. SQL-frågor (7p) Följande är ett utdrag från en databas från ett åkeri. Företaget anställer chaufförer som kör varor per lastbil mellan olika platser. Table name: Driver DriverID DriverLast DriverFirst 1001 Anderson Kim 1002 Smith D.J. 1003 Jones Jaime Table name: Truck TruckID TruckPlate TruckMaxCubicmeter 888 RFG 234 40 889 THA 399 55 890 UNN 002 48 Table name: Travel DriverID TruckID TravelStart TravelCubicmeter TravelDistance 1001 888 2002-08-02 08:00 40 200 1001 888 2002-08-02 12:00 20 210 1002 888 2002-08-03 07:11 40 60 1002 888 2002-08-03 09:20 30 100 1002 888 2002-08-03 14:15 0 80 1003 889 2002-08-03 06:45 50 148 1002 890 2002-08-03 07:00 46 500 a. Visa namnen på alla chaufförer in alfabetisk ordning. (1p) Resultat: Andersson Kim Jones Jaime Smith D.J. b. Lista namnen på chauförrerna tillsammans med totalt antal körningar de haft. (1p) Resultat: Andersson 2 Smith 4 Jones 1 c. Lista bilarnas registreringsnummer samt totalt antal transporterade kubikmetrar och total körsträcka. (2p) Resultat: RFG 234 130 650 THA 399 50 148 UNN 002 46 500 d. Hur många kilometrar har lastbilarna kört med en last under 80% av maximal kapacitet? (Lastbilar som ej matchar ska inte listas.) (3p) Resultat: RFG 234 390
Part 2: Theoretical 5. General data architecture (6p) a. What is the main benefit with the three-layered architecture for Database Management systems. (1p) b. What is the difference between the conceptual and the logical layer, how does this difference support your answer in a. (1p) c. What is the difference between the conceptual and the physical layer, how does this support your answer in a. (1p) d. Imagine a database with 2000 students and 150 courses. The database consists of information which students have passed the courses. We would like a teacher to only access information of his courses and a student only to access information of his results. Describe briefly what this database looks like on each of the layers in the architecture. (3p) 6. Data structures (8p) Given the following relation: PERSON(PNUM,, Age, Phone, Code, Desc) PNUM is CHAR(10), 10 bytes. is CHAR(30), 30 bytes. Age is INTEGER, 2 bytes. Phone is CHAR(15), 15 bytes. Code is CHAR(8), 8 bytes. Desc is CHAR(35), 35 bytes. This relation contains 10000 persons. Each disk block is 5000 bytes, assume a pointer size of 5 bytes. Non-spanning disk blocks. a. Create a primary index on PNUM. Describe briefly your index. (1p) b. Create a secondary index on Age. For each age, assume that there are 140 persons of that age. Describe shortly your secondary index. (1p) c. How many disk accesses do we need to find a person with PNUM= 1122334455? (3p) d. How many disk accesses do we need to find all persons that are 30 years old? (3p)
Del 2: Teoretisk 5. Generell databasarkitektur (6p) a. Vad är den största fördelen med en arkitektur i tre lager för databashanteringssystem? (1p) b. Vad är skillnaden mellan den konceptuella och den logiska nivån? Hur stödjer denna skillnad ditt svar i a. (1p) c. Vad är skillnaden mellan den logiska och den fysiska nivån? Hur stödjer denna skillnad ditt svar i a. (1p) d. Antag att vi har en databas med 2000 studenter och 150 kurser. Databasen innehåller information om vilka studenter som klarat vilka kurser. Wi vill att lärare endast kan se resultat för de kurser han undervisar, medan studenterna bara kan se sina egna resultat. Beskriv kortfattat hur denna databas kan se ut på de tre olika nivåerna av databasen. (3p) 6. Data strukturer (8p) Givet följande relation: PERSON(PNUM,, Age, Phone, Code, Desc) PNUM är CHAR(10), 10 bytes. är CHAR(30), 30 bytes. Age är INTEGER, 2 bytes. Phone är CHAR(15), 15 bytes. Code är CHAR(8), 8 bytes. Desc är CHAR(35), 35 bytes. Relationen innehåller 10000 personer. Varje block är 5000 bytes, antag att pekarstorleken (pointer size) är 5000 bytes. Element kan ej delas (non-spanning) mellan diskblock. a. Skapa ett primärindex på PNUM. Beskriv det kortfattat. (1p) b. Skapa ett sekundärindex på Age. För varje ålder antag att det finns ungefär 140 personer av denna ålder. Beskriv kortfattat ditt sekundärindex. (1p) c. Hur många diskaccesser behövs för att hitta en person med PNUM= 1122334455? (3p) d. Hur många diskaccesser behövs för att hitta alla personer som är 30 år gamla? (3p)
7. Transactions concurrency and recovery (6p) a. Distinguish in your own words, serial schedules and serializable schedules. This distinction should also answer the question: What is the context for using serializability? (3p) b. Explain the two-phase locking protocol and the context in which it occurs. (3p) 8. Relational algebra (5p) a. Express the following relational calculus query in relational algebra, SQL and in words: {t (t ACCOUNT) & (t.amount > 10,000)} (3p) b. The following query in relational calculus cannot be expressed in relational algebra: {t (t ACCOUNT)} where t is any tuple and ACCOUNT is a relation. Explain why this is so. (HINT: Such a query cannot be safe.) Can the query be expressed in SQL? Why? (2p)
7. Transaktioner, parallellitet och återställning a. Beskriv, med egna ord skillnaden mellan seriella (serial) scheman och serialiserbara (serializable) scheman. Ditt svar ska också förklara i vilket sammanhang serialiserbarhet används. (3p) b. Förklara protokollet för tvåfaslåsning (two-phase locking) och i vilket sammanhang det används. (3p) 8. Relationsalgebra (5p) a. Uttryck följande från relationskalkylen i relationsalgebra, SQL och med vanlig svenska: {t (t ACCOUNT) & (t.amount > 10,000)} där t är en tuple och ACCOUNT är en relation b. Följande fråga i relationskalkyl kan inte uttryckas i relationsalgebra: (3p) {t (t ACCOUNT)} Förklara varför? (TIPS: en sådan fråga kan ej vara säker (SAFE)) Kan frågan uttryckas i SQL? Varför? (2p)