Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Joe Celko s SQL for Smarties - Advanced SQL Programming P19. In the SQL database community, Joe Celko is a well-known columnist and purveyor of valuable insights. In Joe Celko's SQL for Smarties: Advanced SQL Programming, he picks up where basic SQL training and experience leaves many database professionals and offers tips, techniques, and explanations that help readers extend their capabilities to top-tier SQL programming. Although Celko denies that the book is about database theory, he nevertheless alludes to theory often to buttress his practical points. This title is not for novices, as the author points out. Instead, its intended audience. | 152 CHAPTER 4 TEMPORAL DATA TYPES IN SQL UPDATE Lots SET to_date DATE 1998-10-01 WHERE lot_id 234 AND from_date DATE 1998-10-01 AND to_date DATE 1998-10-01 UPDATE Lots SET from_date DATE 1998-10-22 WHERE lot_id 234 AND from_date DATE 1998-10-22 AND to_date DATE 1998-10-22 DELETE FROM Lots WHERE lot_id 234 AND from_date DATE 1998-10-01 AND to_date DATE 1998-10-22 Case 1 is reflected in the first two statements the second statement also covers case 2. The third statement handles case 3 and the fourth case 4. All four statements must be evaluated in the order shown. They have been carefully designed to cover each case exactly once. A sequenced update is the temporal analog of a nontemporal update with a specified period of applicability. Let us again consider steering the cattle in lot 799. UPDATE Lots SET gender_code s WHERE lot_id 799 We now convert this to a sequenced update. As with sequenced deletions there are more cases to consider for sequenced updates as compared with current updates. The four cases shown below are handled differently in an update. In case 1 the initial and final portions of the period of validity are retained via two insertions and the affected portion is updated. In case 2 only the initial portion is retained in case 3 only the final portion is retained. In case 4 the period of validity is retained as it is covered by the period of applicability. In summary we need to 1. Insert the old values from the from_date to the beginning of the period of applicability. 4.4 The Nature of Temporal Data Models 153 2. Insert the old values from the end of the period of applicability to the to_date. 3. Update the explicit columns of rows that overlap the period of applicability 4. Update the from_date to begin at the beginning of the period of applicability of rows that overlap the period of applicability. 5. Update the to_date to end at the end of the period of applicability of rows that overlap the period of applicability. Case 1 .