creating your mysql database practical design tips and techniques phần 9 pdf

11 266 0
creating your mysql database practical design tips and techniques phần 9 pdf

Đ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

Supplemental Case Study [ 78 ] The sections available on a plane depend not only on the plane model but also on the airline. This ticket is non-refundable. The data element obtained from the above sentence is: ticket_refundability Flight 456 can be boarded at gate number 74, 35 minutes before takeoff. The data elements obtained from the above sentence are: ight_number gate_id boarding_time In economy class, passengers are entitled to one bag inside the cabin and two registered bags – total weight 50 kg max. Mr Smith has one registered bag, bearing the tag AQ636-84763. The data elements obtained from the above sentence are: plane_section max_number_in_cabin_bags max_number_registered_bags max_weight_registered_bags_kg tag_id We have detected that "class" is a synonym for "section". There are information screens in the airport that indicate the state of each ight: on time, boarding, delayed, or cancelled. The data element obtained from the above sentence is: ight_status • • • • • • • • • • Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Chapter 6 [ 79 ] Will need to be coded (id and description). Two meals are served on this ight. Air Quebec has arrangements with Montreal Chef Service for the preparation and delivery of food. The data elements obtained from the above sentence are: number_meals airline_name meal_supplier Air Quebec owns four Fontax APM-300 aircraft but aircraft #302 (code-named Charlie) is scheduled for repairs in October 2007. The data elements obtained from the above sentence are: airline_name plane_brand plane_model plane_id description plane_event plane_event_start_moment plane_event_end_moment Each plane is affectionately nicknamed, the element for this will be "description". About the repairs, we generalize them with the concept of events, having a starting and ending moment. Passenger Smith can use the quick reference code A6BCUD and his last name to access his ight information on the airline web site. The data elements obtained from the above sentence are: passenger_last_name web_site_quick_reference • • • • • • • • • • • • • Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Supplemental Case Study [ 80 ] Preliminary List of Data Elements We list here the data elements as they can be deduced from the document gathering phase. In many cases, they are not in a format already suitable for the nal model because they are prexed with a table name. For example, a data element identied as pilot_last_name will become the column last_name in the pilot table. Sample values and more detailed information about each data element appear in the next section. Data elements ight_departure_moment seat_id ight_arrival_moment plane_section departure_airport_code ticket_refundability arrival_airport_code gate_id airline_code boarding_time airline_name max_number_in_cabin_bags airport_name max_number_registered_bags plane_brand max_weight_registered_bags_kg plane_model tag_id pilot_last_name ticket_issued_on pilot_rst_name number_meals ight_attendant_last_name web_site_quick_reference ight_attendant_rst_name meal_supplier passenger_last_name plane_id passenger_rst_name plane_event passenger_id plane_event_start_moment booking_agency_name plane_event_end_moment ticket_number ight_status Tables and Sample Values To prepare the list of tables, we start with the physical objects or persons we can observe in the sentences built from the documents gathering phase. Then we have a look at all the elements and build new tables to accommodate them. In the following table descriptions, the table layout is followed by design comments when appropriate. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Chapter 6 [ 81 ] Code Tables Usually the following tables are designed rst because they are easier to model and they are needed for establishing the relations from more complex tables. table: airport column name sample value *id 1 international_code YUL description Montreal-Trudeau The airport table could contain other columns like the address, phone, and website. table: airline column name sample value *id 1 description Air-Quebec table: plane_brand column name sample value *id 1 description Fontax We avoid naming this table as brand because it's a too generic name. table: meal_supplier column name sample value *id 9 description Montreal Chef Service table: booking_agency column name sample value *id 1 description Fantastic Tour Again, this table could have more details about the agency, like phone and address. We could also merge this table with meal_supplier table by adding a code identifying the type of company, but it's not done in the present model. table: ticket_type column name sample value *id 1 description one-way Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Supplemental Case Study [ 82 ] table: crew_category column name sample value *id 1 description Pilot To avoid columns like pilot_last_name, copilot_first_name, we form a crew_category table. See also the related flight_crew table later in this chapter. table: ticket_refundability column name sample value *id 1 description non-refundable table: ight_status column name sample value *id 1 description boarding table: event column name sample value *id 1 description repair If we need to include other types of events in the model, this event table will have to be renamed as something more precise like plane_event, and a new name will be needed for our current plane_event table that is used to associate an event with a plane. Themed Tables These tables are more comprehensive than the code tables. Each one refers to a specic theme that needs more columns than a simple code table. table: plane column name sample value *id 302 airline_id 1 brand_id 1 model_id 2 description Charlie This table identies which aircraft belongs to which airline, with the description being an internal means of describing this particular aircraft within the airline. Other elds like an aircraft serial number can be added here. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Chapter 6 [ 83 ] table: passenger column name sample value *id 1302 last_name Smith rst_name Peter passport_info CDN234234 table: crew column name sample value *id 9 category_id 1 last_name Murray rst_name Dan Passengers and crew members cannot be physically merged into one table even if they belong to the same ight because the set of columns used to describe a passenger diverges from the one associated to a crew member. We'll cover in the Sample Queries section how to produce a combined list of all persons on a plane. table: ight column name sample value *id 34 airline_id 1 number 456 departure_moment 2007-10-02 22:45 arrival_moment 2007-10-03 11:30 departure_airport_id 1 arrival_airport_id 2 plane_id 302 meal_supplier_id 9 number_meals 2 departure_gate 74 arrival_gate B65 boarding_moment 2007-10-02 22:10 status_id 1 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Supplemental Case Study [ 84 ] The notion of ight is central to this system, thus we'll have a flight table. This means that we have to determine a primary key and, at rst sight, the ight number would be a good candidate – but it's not and the reason for this is that the ight number is not painted on an aircraft; it's only a logical way of expressing the movement of a plane between two airports, and also the persons or companies related to this movement. We note that the ight number is kept short – three or four digits for improved reference on all printed matter and on airport information screens; thus, this ight number is only meaningful when accompanied by supplemental information, like the airline code (AQ) or company name, and a date. Keeping in mind that there will be other tables associated with this ight table, we have two choices here for the primary key: create a surrogate key (an articial primary key whose value is not derived from other table's data) use a combination of columns – airline_id, ight_number, departure_moment It is better to create a surrogate key, id. This id will be propagated to the related tables in just one column, which could help to speed up retrieval times because there is just one eld to compare between tables. Using the ight's id will also simplify the writing of queries. Of course we include the ight number – the information known to the public in the flight table but not as a primary key. table: reservation column name sample value *ight_id 34 *passenger_id 1302 web_site_quick_reference KARTYU ticket_number 014 88417654 ticket_issued_moment 2007-01-01 12:00 booking_agency_id 1 ticket_refundability_id 1 ticket_type_id 1 seat 19A section_id 2 It would be a mistake to include columns such as passenger1, passenger2 or seat_1a, seat_1b in the ights table. This is why we use the reservation table to hold passenger information related to a specic ight. This table could also be named flight_passenger. • • Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Chapter 6 [ 85 ] Normally we would not need the section_id in the reservation table, since wesince we can refer to it via the seat_id but the seat_id may be unknown at the time of reservation, so seat assignment can be delayed until the boarding pass is issued. Composite-Key Tables These tables have more than one key because some key segments refer to a code or themed table. table: plane_brand_ model column name sample value *brand_id 1 *id 2 description APM-300 Here, the brand_id and a unique id form the primary keys for the plane model. We want to know to which brand this model refers, and still keep integers for the keys instead of using APM-300 as a key value. table: plane_section column name sample value *airline_id 1 *id 1 description economy Each airline can potentially describe the sections of their planes the way they want – some are using hospitality instead of economy. table: airline_brand_model_ restriction column name sample value *airline_id 1 *brand_id 1 *model_id 2 max_number_in_cabin_bags 1 max_number_registered_bags 2 max_weight_registered_bags_kg 50 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Supplemental Case Study [ 86 ] table: plane_section_seat column name sample value *airline_id 1 *brand_id 1 *model_id 2 *section_id 1 *seat 19A The plane_section_seat table describes which seats are located in a specic section of the aircraft. This is per airline, brand, model, and section, because different airlines could possess the same kind of aircraft but use different seat numbers or have a larger business section than others airlines. Also, in some cases, seats 1A and 1C may exist but 1B may not. Thus, we need this table to hold the complete list of existing seats. table:ight_crew column name sample value *ight_id 34 *crew_id 9 With these sample values, we can deduce that Dan Murray is the pilot for ight 456 of Air-Quebec. Another possible column in this table would be the status of this crew member for this ight: arrived on time, cancelled, or replaced. table: plane_event column name sample value *plane_id 302 *event_id 1 *start_moment 2008-10-01 end_moment 2008-10-31 table: reservation_registered_ bags column name sample value *ight_id 34 *passenger_id 1302 *tag AQ636-84763 Other columns for tag tracking could be added here. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Chapter 6 [ 87 ] Airline System Data Schema Here again we use phpMyAdmin's PDF schema feature to display the relations between tables and the keys involved. Sample Queries As a complement to the list of tables and the database schema, let's see our tables in action! We will enter sample values into the tables, and then build some SQL queries in order to pull the needed data. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com [...]...Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Supplemental Case Study Inserting Sample Values We use the sample values described in the above list of tables Please refer to this book's support site��http://www.packtpub.com/support) for the code download ( � which contains the tables' definition and sample values Boarding Pass A passenger... plane_section on (airline.id = plane_section.airline_id and reservation.section_id = plane_section.id) where reservation.web_site_quick_reference = 'KARTYU' Executing this query retrieves these results: Passenger List Here, the airline wants a list of passengers for a specific flight; we use flight_id,� which is the primary key of the flight table, and not the flight ��������������� number��������� because . is: ight_status • • • • • • • • • • Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Chapter 6 [ 79 ] Will need to be coded (id and description). Two meals are served on. plane_brand_ model column name sample value *brand_id 1 *id 2 description APM-300 Here, the brand_id and a unique id form the primary keys for the plane model. We want to know to which brand this. 302 meal_supplier_id 9 number_meals 2 departure_gate 74 arrival_gate B65 boarding_moment 2007-10-02 22:10 status_id 1 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Supplemental

Ngày đăng: 12/08/2014, 11:20

Từ khóa liên quan

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

Tài liệu liên quan