Modern database management solution book

93 326 1
Modern database management solution book

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

PART III SOLUTIONS TO REVIEW QUESTIONS AND EXERCISES Database Systems: Instructor's Guide - Part III Solutions to Review Questions and Exercises Part One Background Chapter Introduction to Databases Chapter Database Environment Chapter The Relational Model Chapter Database Planning, Design, and Administration 12 Part Two Methodology 14 Chapter Entity-Relationship Modeling 14 Chapter Normalization 17 Chapter Methodology - Conceptual Database Design 22 Chapter Methodology - Logical Database Design for Relational Model 23 Chapter Methodology - Physical Database Design for Relational DBMSs 25 Chapter 10 Conceptual Database Design Methodology - Worked Example 27 Chapter 11 Logical Database Design Methodology - Worked Example 29 Chapter 12 Physical Database Design Methodology – Worked Example 32 Part Three Database Languages 33 Chapter 13 SQL 33 Chapter 14 Advanced SQL 39 Chapter 15 QBE 46 Part Four Selected Database Issues 47 Chapter 16 Security 47 Chapter 17 Transaction Management 49 Chapter 18 Query Processing 54 Part Five Current Trends 62 Chapter 19 Distributed DBMSs - Concepts and Design 62 Chapter 20 Distributed DBMSs - Advanced Concepts 67 Chapter 21 Introduction to Object DBMSs 73 Chapter 22 Object-Oriented DBMSs 74 Database Systems: Instructor's Guide - Part III Chapter 23 Object-Relational DBMSs 84 Part Six Future Trends 89 Chapter 24 Web Technology and DBMSs 89 Chapter 25 Data Warehousing 91 Chapter 26 OLAP and Data Mining 93 Database Systems: Instructor's Guide - Part III Part One Background Chapter Introduction to Databases Review Questions 1.1 List four examples of database systems other than those listed in Section 1.1 Some examples could be: • • • • 1.2 A system that maintains component part details for a car manufacturer; An advertising company keeping details of all clients and adverts placed with them; A training company keeping course information and participants' details; An organization maintaining all sales order information Discuss each of the following terms: Data For end users, this constitutes all the different values connected with the various objects/entities that are of concern to them (See also Section 1.3.3) Database (See Section 1.3.1) Database Management System (See Section 1.3.2) Data Independence This is essentially the separation of underlying file structures from the programs that operate on them, also called program-data independence (See also Sections 1.2.2 and 1.3.1) Security The protection of the database from unauthorized users, which may involve passwords and access restrictions (See also Section 1.6) Integrity The maintenance of the validity and consistency of the database by use of particular constraints that are applied to the data (See also Section 1.6) Views These present only a subset of the database that is of particular interest to a user Views can be customized, for example, field names may change, and they also provide a level of security preventing users from seeing certain data (See also Section 1.3.2) 1.3 Describe the approach taken to the handling of data in the early file-based systems Discuss the disadvantages of this approach Focus was on applications for which programs would be written, and all the data required would be stored in a file or files owned by the programs (See also Section 1.2) Clearly, each program was responsible for only its own data, which could be repeated in other program’s data files Different programs could be written in different languages, and would not be able to access another program’s files This would be true even for those programs written in the same language, because a program needs to know the file structure before it can access it (See also Section 1.2.2) 1.4 Describe the main characteristics of the database approach and contrast it with the file-based approach Focus is now on the data first, and then the applications The structure of the data is now kept separate from the programs that operate on the data This is held in the system catalog or data dictionary Programs can now share data, which is no longer fragmented There is also a reduction in redundancy, and achievement of program-data independence (See also Section 1.3) 1.5 Describe the five components of the DBMS environment and discuss how they relate to each other See Section 1.3.3 1.6 Discuss the roles of the following personnel in the database environment: Database Systems: Instructor's Guide - Part III Data Administrator Database Administrator Logical Database Designer Physical Database Designer Application Programmer End Users 1.7 See Section 1.4.1 See Section 1.4.1 See Section 1.4.2 See Section 1.4.2 See Section 1.4.3 See Section 1.4.4 Discuss the advantages and disadvantages of database processing See Section 1.6 Exercises 1.8 Interview some users of database systems Which DBMS facilities they find most useful and why? Which DBMS facilities they find least useful and why? What these users perceive to be the advantages and disadvantages of the DBMS? Select a variety of users for a particular DBMS If the users are using different DBMSs, group the answers for the different systems, which will give an overall picture of specific systems 1.9 Write a small program that allows entry and display of renter details including a renter number, name, address, telephone number, preferred number of rooms and maximum rent The details should be stored in a file Enter a few records and display the details Now repeat this process but rather than writing a special program, use any DBMS that you have access to What can you conclude from these two approaches? The program can be written in any appropriate programming language, such as Pascal, FORTRAN, C It should adhere to basic software engineering principles including being wellstructured, modular, and suitably commented It is important to appreciate the process involved even in developing a small program such as this The DBMS facilities to structure, store, and retrieve data are used to the same effect The differences in the approaches, such as the effort involved, potential for extension, ability to share the data should be noted 1.10 Study the DreamHome case study presented in Section 1.7 In what ways would a DBMS help this organization? What data can you identify that needs to be represented in the database? What relationships exist between the data? What queries you think are required? It may be useful to review the file-based approach and the database approach here before tackling the first part of the exercise Careful reading and thinking about how people might use the applications should help in carrying out the rest of the exercise 1.11 Study the Wellmeadows Hospital case study presented in Appendix A In what ways would a DBMS help this organization? What data can you identify that needs to be represented in the database? What relationships exist between the data? The approach used for Exercise 1.10 should be used for this exercise also Database Systems: Instructor's Guide - Part III Chapter Database Environment Review Questions 2.1 Discuss the concept of data independence and explain its importance in a database environment See Section 2.1.5 2.2 To address the issue of data independence, the ANSI-SPARC 3-level architecture was proposed Compare and contrast the levels of this model See Section 2.1 2.3 What is a data model? Discuss the main types of data models An integrated collection of concepts for describing data, relationships between data and constraints on the data in an organization (See also Section 2.3) Object-based data models such as the entity-relationship model (see Section 2.3.1) Record-based data models such as the relational data model, network data model, and hierarchical data model (see Section 2.3.2) 2.4 Discuss the function and importance of conceptual modeling See Section 2.3.4 2.5 Describe the types of facilities you would expect to be provided in a multi-user Database Management System Data Storage, Retrieval and Update A User-Accessible Catalog Transaction Support Concurrency Control Services Recovery Services Authorization Services Support for Data Communication Integrity Services Services to Promote Data Independence Utility Services See also Section 2.4 2.6 Of the facilities in 2.4, which ones you think would not be needed in a standalone PC Database Management System? Provide justification for your answer Concurrency Control Services - only single user Authorization Services - only single user, but may be needed if different individuals are to use the DBMS at different times Utility Services - limited in scope Support for Data Communication - only standalone system 2.7 Describe the main components in a DBMS and suggest which components are responsible for each facility identified in question 2.5 Query Processor, DML Preprocessor, Query Optimizer, Data Manager Dictionary Manager Data Manager Scheduler Utilities Authorization Control Utilities Integrity Checker Database Manager, DDL Compiler, File Manager Data Storage, Retrieval and Update A User-Accessible Catalog Transaction Support Concurrency Control Services Recovery Services Authorization Services Support for Data Communication Integrity Services Services to Promote Data Independence Database Systems: Instructor's Guide - Part III Utility Services See also Sections 2.5 and 2.4 2.8 What is meant by the term "client-server architecture" and what are the advantages of this approach? Compare the client-server architecture with two other architectures The client is a process that requires some resource, and the server provides the resource Neither need reside on the same machine Advantages include: • • • • Better performance Likely reduction in hardware costs Reduction in communication costs Better consistency See also Section 2.6 2.9 Discuss the function and importance of the data dictionary See Section 2.7 Exercises 2.10 Analyze the DBMSs that you are currently using Determine each system’s compliance with the functions that we would expect to be provided by a DBMS What types of languages does each system provide? What type of architecture does each DBMS use? Check the accessibility and extensibility of the data dictionary Is it possible to export the data dictionary to another system? To this you will need to obtain appropriate information about each system There should be manuals available or possibly someone in charge of each system who could supply information 2.11 Write a program that stores names and telephone numbers in a database Write another program that stores names and addresses in a database Modify the programs to use external, conceptual, and internal schemas What are the advantages and disadvantages of this modification? The programs can be written in any suitable language and should be well structured and appropriately commented Two distinct files result The structures can be combined into one containing name, address, and tel_no, which can be the representation of both the internal and conceptual schemas The conceptual schema should be created separately with a routine to map the conceptual to the internal schema The two external schemas also must be created separately with routines to map the data between the external and the conceptual schema The two programs should then use the appropriate external schema and routines 2.12 Write a program that stores names and dates of birth in a database Extend the program so that it stores the format of the data in the database; in other words, create a data dictionary Provide an interface that makes this data dictionary accessible to external users Again, the program can be written in any suitable language It should then be modified to add the data format to the original file This should not be difficult, if the original program is well structured The interface for other users operates on the data dictionary and is separate from the original program A menu-based interface is adequate 2.13 How would you modify this program to conform to a client-server architecture? What would be the advantages and disadvantages of this modification? The server should hold the data dictionary and the programs that operate on it The user interface should be separate, on the client, and call the data dictionary programs Database Systems: Instructor's Guide - Part III Chapter The Relational Model Review Questions 3.1 Discuss each of the following concepts in the context of the relational data model: (a) (b) (c) (d) (e) Relation Attribute Tuple Intension and Extension Degree and Cardinality Each term defined in Section 3.2.1 3.2 Discuss the differences between the candidate keys and the primary key of a relation Explain what is meant by a foreign key How foreign keys of relations relate to candidate keys? The primary key is the candidate key that is selected to identify tuples uniquely within a relation A foreign key is an attribute or set of attributes within one relation that matches the candidate key of some (possibly the same) relation 3.3 Define the two principal integrity rules for the relational model Discuss why it is desirable to enforce these rules Two rules are Entity Integrity (Section 3.3.2) and Referential Integrity (Section 3.3.3) 3.4 Define the five basic relational algebra operations Define the remaining three relational algebra operations in terms of the five basic operations Five basic operations are: • • Selection and Projection (Unary) Cartesian Product, Union and Set Difference (Binary) There is also the Join, Intersection and Division operations: • Can rewrite θ-Join in terms of the basic selection and Cartesian product operations: R • F S = σF(R × S) Can express the intersection operator in terms of the set difference operation: R ∩ S = R - (R - S) • Can express the division operator in terms of the basic operations: T1 = ΠC(R) T2 = ΠC( (S x T1) - R) T = T1 - T2 3.5 What is a view? Discuss the difference between a view and a base relation Explain what happens when a user accesses a database through a view View is the dynamic result of one or more relational operations operating on the base relations to produce another relation Base relation exists as a set of data in the database A view does not contain any data, rather a view is defined as a query on one or more base relations and a query on the view is translated into a query on the associated base relations Database Systems: Instructor's Guide - Part III Exercises The following tables form part of a database held in a relational DBMS:Hotel Room Booking Guest where (Hotel_No, Name, Address) (Room_No, Hotel_No, Type, Price) (Hotel_No, Guest_No, Date_From, Date_To, Room_No) (Guest_No, Name, Address) and Hotel contains hotel details and Hotel_No is the primary key Room contains room details for each hotel and (Hotel_No, Room_No) forms the primary key Booking contains details of the bookings and the primary key comprises (Hotel_No, Guest_No, and Date_From) Guest contains guest details and Guest_No is the primary key 3.6 Generate the relational algebra for the following queries: (a) List all hotels HOTEL (b) List all single rooms with a price below £20 per night σtype='S' AND price < 20(ROOM) (c) List the names and addresses of all guests Πname, address(GUEST) (d) List the price and type of all rooms at the Grosvenor Hotel Πprice, type(ROOM (e) hotel_no (σname='Grosvenor Hotel'(HOTEL))) List all guests currently staying at the Grosvenor Hotel GUEST guest_no (σdate_from = '01-01-99' ( BOOKING hotel_no (σname='Grosvenor Hotel'(HOTEL)))) (substitute '01-01-99' for today’s date) (f) List the details of all rooms at the Grosvenor Hotel, including the name of the guest staying in the room, if the room is occupied (ROOM // Outer Join hotel_no (σname='Grosvenor Hotel'(HOTEL)) Πguest.name, hotel.hotel_no, room.room_no( (GUEST guest_no (σdate_from = '01-01-99' ( BOOKING hotel_no (σname='Grosvenor Hotel'(HOTEL)))) (substitute '01-01-99' for today’s date) (g) List the guest details (Guest_No, Name and Address) of all guests staying at the Grosvenor Hotel Πguest_no, name, address(GUEST guest_no (σdate_from = '01-01-99' ( BOOKING hotel_no (σname='Grosvenor Hotel'(HOTEL))))) (substitute '01-01-99' for today’s date) Database Systems: Instructor's Guide - Part III 3.7 Using relational algebra, create a view of all rooms in the Grosvenor Hotel, excluding price details What would be the advantages of this view? Πroom_no, hotel_no, type(ROOM hotel_no (σname='Grosvenor Hotel'(HOTEL))) Security - hides the price details from people who should not see it Reduced complexity - a query against this view is simpler than a query against the two underlying base relations 3.8 Produce the equivalent tuple and domain relational calculus statements for the above queries Tuple Relational Calculus (a) RANGE OF H IS HOTEL {H} (b) RANGE OF R IS ROOM {R | R.Type = 'S' AND R.Price < 20} (c) RANGE OF G IS GUEST {G.Name, G.Address} (d) RANGE OF H IS HOTEL RANGE OF R IS ROOM {R.Price, R.Type | ∃H (R.Hotel_No = H.Hotel_No AND H.Name = 'Grosvenor Hotel')} (e) RANGE OF H IS HOTEL RANGE OF G IS GUEST RANGE OF B IS BOOKING {G | B ((B.Date_From = '01-01-99') AND (B.Guest_No = G.Guest_No) AND ∃H (B.Hotel_No = H.Hotel_No AND H.Name = 'Grosvenor Hotel'))} (f) Need to use Union of a relation containing all Rooms that are occupied with a relation extended by a NULL name for all unoccupied rooms (g) RANGE OF H IS HOTEL RANGE OF G IS GUEST RANGE OF B IS BOOKING {G.Guest_No, G.Name, G.Address | B((B.Date_From = '01-01-99') AND (B.Guest_No = G.Guest_No) AND ∃H (B.Hotel_No = H.Hotel_No AND H.Name = 'Grosvenor Hotel'))} Domain Relational Calculus (a) {Hotel_No, Name, Address | ∃Hotel_No, Name, Address (HOTEL(Hotel_No, Name, Address)} (b) {Room_No, Hotel_No, Type, Price | ∃Room_No, Hotel_No, Type, Price (ROOM(Room_No, Hotel_No, Type, Price) AND Type = 'S' AND Price < 20)} (c) {Name, Address | ∃Name, Address (GUEST(Name, Address)} (d) {Price, Type | ∃Room_No, Type, Price, Hotel_No 10 Database Systems: Instructor's Guide - Part III 22.14 Produce an object-oriented database design for the Wellmeadows Hospital student project presented in Appendix A State any assumptions necessary to support your design The following is a sample schema, not all methods are shown: interface Ward { (extent wards key WardNo) attribute string WardNo; attribute string WName; attribute string Location; attribute integer TotalBeds; attribute string TelExtn; relationship List has_waiting_list inverse Waiting_List::is_waiting_for {order_by Waiting_List::ListDate, WardReq}; relationship List has_staff_rota inverse Staff_Rota::on_shift_for {order_by Staff_Rota::WardNo, WeekNo}; relationship Set needs_req inverse Requisition::req_for; relationship Nurse is_managed_by inverse Nurse::manages; create_new_ward(); destroy_ward(in Ward) raises(no_such_ward); assign_charge_nurse(in Nurse) raises(no_such_nurse); } interface Staff { (extent staff key StaffNo, NIN) attribute string StaffNo; attribute ; attribute string Address; attribute string TelNo; attribute date DOB; attribute char Sex; attribute string NIN; attribute string Position; attribute float Salary; attribute integer SScale; attribute integer WeekHrs; attribute char ContType; attribute char TypePay; attribute Set> Qualification; attribute Set> Work_Experience; relationship List has_rota inverse Staff_Rota::shift_for {order_by Staff_Rota::StaffNo, WeekNo}; destroy_staff(in Staff) raises(no_such_person); increase_salary(in Staff, in float); } interface Nurse::Staff { (extent nurses) relationship Ward manages inverse Ward::is_managed_by; relationship Set makes_req inverse Requisition::made_by; 79 Database Systems: Instructor's Guide - Part III create_new_nurse(); make_requisition(in Nurse, in Pharmaceutical) raises(no_such_drug); } interface Consultant::Staff { (extent consultants) relationship List sees inverse Appointment::is_seen_by {order_by Appointment::ConsStaffNo, Adate, ATime}; create_new_consultant(); cancel_appointment(in Consultant, in Appointment); } interface Staff_Rota { (extent rotas key (StaffNo, WeekNo)) attribute integer Shift; attribute integer WeekNo; attribute string StaffNo; attribute string WardNo; relationship Ward on_shift_for inverse Ward::has_staff_rota; relationship Staff shift_for inverse Staff::has_rota; create_new_rota(); } interface Patient { extent patients; key PatNo; attribute string PatNo; attribute ; attribute string Address; attribute string TelNo; attribute date DOB; attribute char Sex; attribute char MStatus; attribute date DateReg; attribute > Next-OfKin; attribute Set outpatient_appointment; relationship Doctor has_gp inverse Doctor::gp_for; relationship List has_appt inverse Appointment::is_appt_for; relationship List takes inverse Medication::is_taken_by; relationship List waits_for inverse Waiting_List::is_on; create_new_patient(); change_doctor(in from:Doctor, in to:Doctor) raises(unknown_doctor); cancel_appointment(in Appointment) raises(no_appointment); } interface Doctor { (extent gps key (DocName, ClinicNo)) attribute string DocName; attribute string ClinicNo; 80 Database Systems: Instructor's Guide - Part III attribute string Address attribute string TelNo; relationship List gp_for inverse Patient::has_gp; create_new_doctor(); } interface Appointment { (extent appointments key AppNo) attribute string AppNo; attribute date ADate; attribute time ATime; attribute string RoomNo; relationship Patient is_appt_for inverse Patient::has_appt; relationship Consultant is_seen_by inverse Consultant::sees; } interface Waiting_List { (extent waiting key (PatNo, ListDate)) attribute date ListDate; attribute interval Duration; attribute date PlacedDate; attribute date ExLeaveDate; attribute date ActLeaveDate; attribute string BedNo; relationship Ward is_waiting_for inverse Ward::has_waiting_list; relationship Patient is_on inverse Patient::waits_for; add_to_list(in Patient, in Ward) raises(no_such_patient, no_such_ward); remove_from_list(in Patient, in Ward) raises(no_such_patient, no_such_ward); } interface Medication { (extent medications key (PatNo, DrugNo, SDate)) attribute string UnitsDay; attribute string AMethod; attribute date SDate; attribute date FDate; relationship Patient is_taken_by inverse Patient::takes; relationship Pharmaceutical contains inverse Pharmaceutical::contained_in; add_medication(in Patient, in Pharmaceutical) raises(no_such_patient, no_such_drug); change_medication(in Patient, in Pharmaceutical) raises(no_such_patient, no_such_drug);; } interface Pharmaceutical { (extent drugs key DrugNo) attribute string DrugNo; attribute string DName; attribute string Description; attribute string Dosage; 81 Database Systems: Instructor's Guide - Part III attribute string MAdmin; attribute integer QStock; relationship List contained_in inverse Medication::contains; relationship List req_in inverse Requisition::reqs_for; relationship Supplier is_supplied_by inverse Supplier::supplies; create_drug(); remove_drug(in Pharmaceutical) raises(no_such_drug); } interface Non-Surgical/Surgical { (extent supplies key ItemNo) attribute string ItemNo; attribute string IName; attribute string IDescription; attribute integer QStock; attribute string RLevel; attribute float UnitCost; relationship List req_in inverse Requisition::reqs_for; create_item(); remove_Item(in Non-Surgical/Surgical) raises(no_such_item); } interface Requisition { (extent requisitions key ReqNo) attribute string ReqNo; attribute integer QuantReq; attribute date DateOrder; attribute date DateReceive; relationship Ward req_for inverse Ward::needs_req; relationship Nurse made_by inverse Nurse::makes_req; relationship Pharmaceutical reqs_for inverse Pharmaceutical::req_in; relationship Non-Surgical/Surgical reqs_for inverse Non-Surgical/Surgical::req_in; deliver_req(in Requisition) raises(no_such_req); } interface Supplier { (extent suppliers key SupplierNo) attribute string SupplierNo; attribute string SName; attribute string SAddress; attribute string TelNo; attribute string FaxNo; relationship Set supplies inverse Pharmaceutical::is_supplied_by; } 22.15 You have been asked by the Managing Director of DreamHome to investigate and prepare a report on the applicability of an Object-Oriented DBMS for the organization The report should compare the technology of the relational DBMS with that of the Object-Oriented DBMS, and should address the advantages and disadvantages of implementing an OODBMS within the organization, and any perceived problem areas Finally, the report should contain a fully justified set of conclusions on the applicability of the OODBMS for DreamHome 82 Database Systems: Instructor's Guide - Part III A well-presented report is expected Justification must be given for any recommendations made 22.16 Using the rules for schema consistency given in Section 22.4.3, consider each of the following modifications and state what the effect of the change should be to the schema: (a) (b) (c) (d) Adding an attribute to a class Deleting and attribute from a class Making a class S a superclass of a class C Removing a class S from the list of superclasses of a class C See Section 22.4.3 83 Database Systems: Instructor's Guide - Part III Chapter 23 Object-Relational DBMSs Review Questions 23.1 What typical functionality would be provided by an ORDBMS? Many different answers here – see, for example, Section 23.2.1 Expect standard DBMS functionality, plus object management capabilities (types, inheritance, etc), plus ability to extend query optimizer, and define new index types (see Section 23.5) 23.2 What are the advantages and disadvantages of extending the relational data model? See Section 23.1 under Advantages and Disadvantages 23.3 What are the main features of the forthcoming SQL standard? See start of Section 23.4 23.4 Discuss the extensions required to query processing and query optimization to fully support the ORDBMS? See Section 23.5 23.5 What are the security problems associated with the introduction of user-defined methods and suggest some solutions to these problems? See paragraph before start of Section 23.5.1 Exercises 23.6 Analyze the relational DBMSs that you are currently using Discuss the object-oriented facilities provided by the system What additional functionality these facilities provide? This is a small student project, the result of which is dependent on the system analyzed 23.7 Consider the relational schema for the Hotel case study given in the Exercises of Chapter 11 Redesign this schema to take advantage of the new features of SQL3/SQL4 Add user-defined functions that you consider appropriate One possible solution as follows: CREATE DOMAIN HOTEL_NUMBER AS CHAR(4); CREATE DOMAIN ROOM_TYPE AS CHAR(1) CHECK(VALUE IN ('S', 'F', 'D')); CREATE DOMAIN ROOM_PRICE AS DECIMAL(5,2) CHECK(VALUE BETWEEN 10 AND 100); CREATE ROOM_NUMBER AS VARCHAR(4) CHECK(VALUE BETWEEN '1' AND '100'); CREATE DOMAIN GUEST_NUMBER AS CHAR(4); CREATE DOMAIN BOOKING_DATE AS DATETIME CHECK(VALUE > CURRENT_DATE); CREATE TYPE hotel_type( hotel_no HOTEL_NUMBER name VARCHAR(20) address VARCHAR(50) NOT NULL, NOT NULL, NOT NULL); CREATE TABLE hotel OF hotel_type( oid REF(hotel_type) VALUES ARE SYSTEM GENERATED, PRIMARY KEY (hotel_no)); 84 Database Systems: Instructor's Guide - Part III CREATE TYPE rooms_type( room_no ROOM_NUMBER hotel_no REF(hotel_type) type ROOM_TYPE price ROOM_PRICE NOT NULL, NOT NULL, NOT NULL DEFAULT 'S' NOT NULL); CREATE TABLE room OF rooms_type( PRIMARY KEY (room_no, hotel_no), FOREIGN KEY (hotel_no) REFERENCES hotel ON DELETE CASCADE ON UPDATE CASCADE); CREATE TYPE guest_type( guest_no GUEST_NUMBER name VARCHAR(20) address VARCHAR(50) NOT NULL, NOT NULL, NOT NULL); CREATE TABLE guest OF guest_type( oid REF(guest_type) VALUES ARE SYSTEM GENERATED, PRIMARY KEY (guest_no)); CREATE TYPE booking_type( hotel_no REF(hotel_type) guest_no REF(guest_type) date_from BOOKING_DATE date_to BOOKING_DATE room_no ROOM_NUMBER NOT NULL, NOT NULL, NOT NULL, NULL, NOT NULL); CREATE TABLE booking OF booking_type( PRIMARY KEY (hotel_no, guest_no, date_from), FOREIGN KEY (hotel_no) REFERENCES hotel ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (guest_no) REFERENCES guest ON DELETE NO ACTION ON UPDATE CASCADE, FOREIGN KEY (hotel_no, room_no) REFERENCES room ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT room_booked CHECK (NOT EXISTS (SELECT * FROM booking b WHERE b.date_to > booking.date_from AND b.date_from < booking.date_to AND AND b.room_no = booking.room_no AND b.hotel_no = booking.hotel_no)), CONSTRAINT guest_booked CHECK (NOT EXISTS (SELECT * FROM booking b WHERE b.date_to > booking.date_from AND b.date_from < booking.date_to AND AND b.guest_no = booking.guest_no))); 23.8 Create SQL3/SQL4 statements for the queries given in Exercise 13.7 - 13.26 Depends on the solution to the previous question For example, using the above schema, the solution to 13.16 would be: SELECT price, type FROM room r WHERE r–>hotel.name = 'Grosvenor Hotel'; 85 Database Systems: Instructor's Guide - Part III 23.9 Create an insert trigger that sets up a mailshot table recording the names and addresses of all guests who have stayed at the hotel during the days before and after New Year for the past two years The aim of this question is to show the difficulty of creating a trigger that does not necessarily need to be tied to a modification to a table CREATE TRIGGER insert_mailshot_table AFTER INSERT ON booking BEGIN INSERT INTO mailshot (SELECT g.guest_no, g.name, g.address FROM guest g, booking b1, booking b2 WHERE g.guest_no = b1.guest_no AND b1.guest_no = b2.guest_no AND ((b1.date_from =DATE'1998-12-31') OR (b1.date_from >= DATE'1998-12-31' AND b1.date_from = DATE'1997-12-31' AND b1.date_from [...]... conceptual and logical database design phases The aims of conceptual database design are described in Section 4.3.2 and the aims of logical database design are described in Section 4.3.3 4.5 Explain why it is necessary to select the target database management system before commencing with the physical database design phase Describe the main aims of physical database design Physical database design is tailored... Systems: Instructor's Guide - Part III Chapter 8 Methodology - Logical Database Design for Relational Model Review Questions 8.1 Identify the three main phases of database design and discuss the purpose of logical database design The three main phases of database design are conceptual, logical, and physical For purpose of logical database design see Section 8.1 8.2 Describe the steps involved in refining... logical model 23 Database Systems: Instructor's Guide - Part III See Section 8.1 Step 3 and in particular Step 3.1 24 Database Systems: Instructor's Guide - Part III Chapter 9 Methodology - Physical Database Design for Relational DBMSs Review Questions 9.1 Explain the difference between logical and physical database design Why might these tasks be carried out by different people? Logical database design... role played by users in the process of database design The users' involvement throughout the database design phase is critical to providing the 'correct' system In particular, the user should clarify any ambiguities in the specification that describes the required system and also review continually the development of the database design The process of developing the database design is repeated until the... conceptual database design See Section 7.3 7.8 Discuss the purpose of specialization/generalization of entity types, and discuss why this is an optional step in conceptual database design See Section 7.3 Step 1.6 7.9 Identify and describe the purpose of the documentation generated during conceptual database design See Section 7.3 and in particular note the documentation generated at the end of each step 22 Database. .. of which is dependent on the system analyzed 11 Database Systems: Instructor's Guide - Part III Chapter 4 Database Planning, Design, and Administration Review Questions 4.1 Discuss the relationship between the information system lifecycle and the database application lifecycle See Sections 4.1 and 4.2 4.2 Describe the purpose of each of the stage of the database application lifecycle See Section 4.2... helps to plan, manage, control and evaluate database development projects Furthermore, it is a structured approach for analyzing and modeling a set of requirements for a database in a standardized and organized manner See Section 7.1 7.2 Describe the main phases involved database design See Section 7.1.2 7.3 Identify important factors in the success of logical database design See Section 7.1.3 7.4 Discuss... in 12.4 The student should implement the physical database design created in Exercise 12.4 using the target DBMS 32 Database Systems: Instructor's Guide - Part III Part Three Database Languages Chapter 13 SQL Review Questions 13.1 What are the two major components of SQL and what function do they serve? A data definition language (DDL) for defining the database structure A data manipulation language... part of a database held in a relational DBMS: Hotel Room Booking Guest where and (Hotel_No, Name, Address) (Room_No, Hotel_No, Type, Price) (Hotel_No, Guest_No, Date_From, Date_To, Room_No) (Guest_No, Name, Address) Hotel contains hotel details and Hotel_No is the primary key Room contains room details for each hotel and (Hotel_No, Room_No) forms the primary key Booking contains details of the bookings... from bookings for the Grosvenor Hotel today? SELECT SUM(price) FROM booking b, room r, hotel h WHERE (b.date_from = CURRENT_DATE) AND r.hotel_no = h.hotel_no and r.room_no = b.room_no; 35 Database Systems: Instructor's Guide - Part III 13.20 List the rooms that are currently unoccupied at the Grosvenor Hotel SELECT * FROM room r WHERE room_no NOT IN (SELECT room_no FROM booking

Ngày đăng: 25/08/2016, 22:07

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan