1 Proposal of a New SQL/MM Subproject ---SQL/MM Part 7: History April 2005 Berlin, Germany Y. Ishii, T. Kajino, Y. Noguchi, M. Inui, T. Ishizaka K. Suzuki,

Slides:



Advertisements
Similar presentations
Views-basics 1. 2 Introduction a view is a perspective of the database different users may need to see the database differently; this is achieved through.
Advertisements

Active database concepts
COP4540 Database Management System Midterm Review
Oracle Object-Relational Model. - Structures : tables, views, indexes, etc. - Operations : actions that manipulate data stored in structures - Integrity.
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
PL/SQL.
1 Constraints, Triggers and Active Databases Chapter 9.
Advanced Databases Temporal Databases Dr Theodoros Manavis
Structure Query Language (SQL) COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Structured Query Language Chapter Three Part 3 – Inserts, Updates, Deletes.
Chapter 3 An Introduction to Relational Databases.
DAY 16: ACCESS CHAPTER 2 Tazin Afrin October 10,
Project Implementation for COSC 5050 Distributed Database Applications Lab2.
Introduction –All information systems create, read, update and delete data. This data is stored in files and databases. Files are collections of similar.
Chapter 3 An Introduction to Relational Databases.
DEVELOPMENT OF MEMBERSHIP FEES. THE SKELETON OF THE SPREAD SHEET After reading the outline of the memberships fees on the website, I deduced that the.
Creating a Table Create a table, “emp”, containing: –empno – a 4 digit employee number –ename – up to 10 character string –job – up to 9 character string.
Overview of Standard Query Language (SQL) Saeideh Joodaki Instructor: Dr.Yingshu Li.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
SQL (DDL & DML Commands)
CS 101 – Access notes Databases (Microsoft Access) 4 parts of a database database design –Try to understand the ideas behind database design, not just.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
1 WG2 N1536 WG3: KOA-046 Temporal Features in SQL standard Krishna Kulkarni, IBM Corporation May 13, 2011.
“INTRODUCTION TO DATABASE AND SQL”. Outlines 2  Introduction To Database  Database Concepts  Database Properties  What is Database Management System.
USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
Recap of SQL Lab no 8 Advance Database Management System.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents.
CMPE 226 Database Systems October 7 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Advanced SQL: Triggers & Assertions
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
1 Notes on: Clusters Index and Cluster Creation in SQL Elisa Bertino CS Department and CERIAS Purdue University.
Topics Related to Attribute Values Objectives of the Lecture : To consider sorting relations by attribute values. To consider Triggers and their use for.
COMP3030 Database Management System Final Review
Working with SQL Server Database Objects Faculty: Nguyen Ngoc Tu.
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
COP-5725 Practice Exercises
ORDER BY clause in SELECT command: Normally, the result of the query will not be in ordered format. If we want to get the result of the query in specific.
SQL Server 2012 Session: 1 Session: 12 Triggers Data Management Using Microsoft SQL Server.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Databases Flat Files & Relational Databases. Learning Objectives Describe flat files and databases. Explain the advantages that using a relational database.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
CPT-S Advanced Databases 11 Yinghui Wu EME 49.
SQL Triggers, Functions & Stored Procedures Programming Operations.
SQL: Interactive Queries (2) Prof. Weining Zhang Cs.utsa.edu.
Chapter 3 An Introduction to Relational Databases.
Copyright © 2004 Pearson Education, Inc.. Chapter 24 Enhanced Data Models for Advanced Applications.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
1 CS490 Database Management Systems. 2 CS490 Database Normalization.
Trigger used in PosgreSQL
“Introduction To Database and SQL”
Instructor: Jason Carter
Introduction to Oracle9i: SQL
CIS 336 str Competitive Success/snaptutorial.com
CIS 336 str Education for Service- -snaptutorial.com.
CIS 336 str Teaching Effectively-- snaptutorial.com.
Using the Set Operators
“Introduction To Database and SQL”
RELATIONAL ALGEBRA (Chapter 2)
Temporal Databases.
Advanced SQL: Views & Triggers
Flat Files & Relational Databases
Chapter 8 Advanced SQL.
Information Management
Chapter 9: Database Systems
CS240A: Databases and Knowledge Bases A Taxonomy of Temporal DBs
Presentation transcript:

1 Proposal of a New SQL/MM Subproject ---SQL/MM Part 7: History April 2005 Berlin, Germany Y. Ishii, T. Kajino, Y. Noguchi, M. Inui, T. Ishizaka K. Suzuki, T. Kotera, K. Yamahira and K. Shibano Japan ISO/IEC JTC 1/SC 32/WG 4:TXL-014 April 11, 2005

2 The Problem During an update operation, the value of an attribute is overwritten by the new value and the “before” value no longer exists –When the attributes of people (e.g. employees, customers, patients, and criminals) or products are expressed in a table, and –When the values of the attributes (e.g. position title, address, diagnose, crime committed, unit price) change over time

3 Our Proposal We are proposing SQL/MM Part7: History based on SQL language to enable –Creating and maintaining a separate table, which we call “history table”, to store the change history of the base table. –Providing methods for time-related queries to the history table.

4 Approach It is possible to accumulate the change history of an existing table without changing the existing business application. We realize the function using the framework of SQL/MM. –Define the procedure HS_CreateHistory to create and maintain the history table. –Define the following two user-defined types. HS_History type HS_TYPE_ type

5 Several Examples of the General Time-Related Queries Which employee(s) lived in San Francisco on December 31, 1999? Which employee(s) belonged to the Engineering Department No. 1 for 7 years consecutively? Which customer got a promotion to Gold rank during the period between January 1, 2002 through December 31, 2002? Which products has price changes 3 times or more in the last 2 years? Which patients became ill with Illness zz within 3 years after undergoing Medical Treatment yy for Illness xx? After leaving hospital, how many patients with a certain inspection value xx being below yy are still alive 6 months later?

6 Structure of History Table Key_ColColumn_AColumn_BColumn_C K0A0B0C0 Key_ColColumn_AColumn_BColumn_C HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime K0A0B0C :23:51NULL Original base table (current state table) History table History table is a table that holds change history for the original base table. The history row is inserted into the history table when Update operation to the specified column(s) of the original base table occurs. History table is defined as a table which is typed by HS_TYPE_ type, and consists of the following columns: –All columns in the original base table. –column of structured type HS_History, which has attributes of history begin time and history end time.

7 Creation and Maintenance of History Table Key_ColColumn_AColumn_BColumn_C K0A0B0C0 Key_ColColumn_AColumn_BColumn_C HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime K0A0B0C :23:51NULL Original base table (current state table) History table History table is created automatically when the HS_CreateHistory procedure is called. When a history table is created, all rows in the original base table are inserted with history begin time set to the CURRENT_TIMESTAMP. Insertion of history row to history table is automatically executed by triggers that fire when Update/Insert/Delete operation to the original base table is executed.

8 Automatic Maintenance of History Table The following five triggers perform automatic insertion of history row to history table, and maintenance of the consistency of history table. EventProcess Insert to original base table A row in the history table is inserted, and history begin time and history end time are set to CURRENT_TIMESTAMP and NULL respectively. Update to the specified columns of original base table History end time of the latest history row in the history row set is updated to CURRENT_TIMESTAMP. A row in the history table is inserted, and history begin time and history end time are set to CURRENT_TIMESTAMP and NULL respectively. Delete in original base table History end time of the latest history row in the history row set is updated to CURRENT_TIMESTAMP. Before Update to HS_Hist column of history table Forbid updating other than the latest history row in the history row set. After Update to HS_Hist column of history table Maintain the consistency of the values of history begin time and history end time in the history table.

9 More Detailed Explanation of Process for Insert Operation(1) Key_ColColumn_AColumn_BColumn_C K0A0B0C0 K1A1B1C1 Key_ColColumn_AColumn_BColumn_C HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime K0A0B0C :23:51NULL K1A1B1C :38:33NULL Original base table (current state table) History table When Insert operation to the original base table is executed, a row in the history table is inserted.

10 More Detailed Explanation of Process for Insert Operation(2) Key_ColColumn_AColumn_BColumn_C K0A0B0C0 K1A1B1C1 Key_ColColumn_AColumn_BColumn_C HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime K0A0B0C :23:51NULL K1A1B1C :00:00NULL Original base table (current state table) History table When Insert operation to the original base table is executed, a row in the history table is inserted. When a user wants to specify the value of history begin time of the latest history row in the history row set clearly, the value of history begin time is updated by invoking HS_HistoryBeginTime method provided in the HS_TYPE_ type.

11 More Detailed Explanation of Process for Update Operation Key_ColColumn_AColumn_BColumn_C K0A0B0C0 K1A2B2C1 Key_ColColumn_AColumn_BColumn_C HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime K0A0B0C :23:51NULL K1A1B1C :00: :00:00 K1A2B2C :00:00NULL Original base table (current state table) History table When Update operation to the original base table is executed, history end time of the latest row in the history row set is updated to CURRENT_TIMESTAMP, and a row in the history table is inserted. In the same way as the example of Insert operation, if necessary, the value of history begin time can be updated. (History end time of previous history row is also simultaneously update into the same value by the trigger.)

12 More Detailed Explanation of Process for Delete Operation Key_ColColumn_AColumn_BColumn_C K0A0B0C0 Key_ColColumn_AColumn_BColumn_C HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime K0A0B0C :23:51NULL K1A1B1C :00: :00:00 K1A2B2C :00: :00:00 Original base table (current state table) History table When Delete operation to the original base table is executed, history end time of the latest row in the history row set is updated to CURRENT_TIMESTAMP. When a user wants to specify the value of history end time of the latest history row in the history row set clearly, the value of history end time is updated by invoking HS_HistoryEndTime method provided in the HS_TYPE_ type.

13 How to Query to History Table We provide predicates to specify time-related condition as methods of HS_History type. When querying to history table, –You specify the name of history table ‘HS_TBL_ ’ directly. –You specify the table obtained by invoking the method of HS_TYPE_ type.

14 History Types and Methods(1) Method provided in HS_History type: –Predicates: HS_Overlaps: tests whether this period overlaps another period. HS_Contains: tests whether this period contains another whole period. HS_Meets: tests whether the end time of this period is equal to the begin time of another period or another TIMESTAMP value. HS_Precedes: tests whether the whole of this period precedes the begin time of another period. HS_Equals: tests whether this period is equal to another period. –Others: HS_MonthInterval: returns the length of this period as year-month interval. HS_DayInterval: returns the length of this period as day-time interval. HS_Intersect: generates a new HS_History value with period which is overlap of this period and another period.

15 History Types and Methods(2) Method provided in HS_TYPE_ type: –HS_HistoryBeginTime: sets the history begin time of the latest history row in the specified history row set. –HS_HistoryEndTime: sets the history end time of the latest history row in the specified history row set. –HS_Period: generates a restructured history table which stores change history of the specified values.

16 Time-Related Predicates The following figures express the meanings of the time-related predicates provided as methods of the HS_History type. overlapscontainsmeets precedes equals t tt tt

17 Example: How to Store History Data There is a table called “emp”. History Table will be defined on top of this “emp” table. The next 11 slides will explain how History Table is managed.

18 There is a table called “emp” which is managing the employees of a university. EmpIDEmpNameTitleSalaryDept 1TomAssistant4000CS1 Table “emp”

19 At 1996/04/03 09:32:17, the history table is created by calling HS_CreateHistory procedure. EmpIDEmpNameTitleSalaryDept 1TomAssistant4000CS1 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :32:17NULL Table “emp” History table of “emp” CALL HS_CreateHistory( ‘emp’, ARRAY[‘Title’, ‘Salary’, ‘Dept’);

20 User invokes the HS_HistoryBeginTime method of HS_TYPE_emp type to update history begin time of the history rows to ‘ :00:00’. EmpIDEmpNameTitleSalaryDept 1TomAssistant4000CS1 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :00:00NULL Table “emp” History table of “emp” In subsequent slides, the process in which a user updates a value of history begin time after the CURRENT_TIMESTAMP value is stored in the value of history begin time is omitted for the simplification of explanation. HS_TYPE_emp::HS_HistoryBeginTime( 1, TIMESTAMP ‘ :00:00’);

21 At 1997/04/01 00:00:00, Ken joined the faculty of this university. EmpIDEmpNameTitleSalaryDept 1TomAssistant4000CS1 2KenAssistant Professor7000Med2 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :00:00NULL 2KenAssistant Professor7000Med :00:00NULL Table “emp” History table of “emp” INSERT INTO emp( EmpID, EmpName, Title, Salary, Dept) VALUES( 2, ‘Ken’, ‘Assistant Professor’, 7000, ‘Med2’); HS_TYPE_emp::HS_HistoryBeginTime( 2, TIMESTAMP ‘ :00:00’);

22 At 1998/04/01 00:00:00, Ken was promoted from “assistant professor” to “professor”, and his salary was raised to 8,000. EmpIDEmpNameTitleSalaryDept 1TomAssistant4000CS1 2KenProfessor8000Med2 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :00:00NULL 2KenAssistant Professor7000Med :00: :00:00 2KenProfessor8000Med :00:00NULL Table “emp” History table of “emp” UPDATE emp SET Title = ‘Professor’, Salary = 8000 WHERE EmpID = 2; HS_TYPE_emp::HS_HistoryBeginTime( 2, TIMESTAMP ‘ :00:00’);

23 At 1999/04/01 00:00:00, Tom’s salary was raised to 5,000. EmpIDEmpNameTitleSalaryDept 1TomAssistant5000CS1 2KenProfessor8000Med2 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :00: :00:00 1TomAssistant5000CS :00:00NULL 2KenAssistant Professor7000Med :00: :00:00 2KenProfessor8000Med :00:00NULL Table “emp” History table of “emp” UPDATE emp SET Salary = 5000 WHERE EmpID = 1; HS_TYPE_emp::HS_HistoryBeginTime( 1, TIMESTAMP ‘ :00:00’);

24 At 2000/04/01 00:00:00, Tom was promoted from “assistant” to “assistant professor”, and his salary was raised to 6,000. EmpIDEmpNameTitleSalaryDept 1TomAssistant Professor6000CS1 2KenProfessor8000Med2 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :00: :00:00 1TomAssistant5000CS :00: :00:00 1TomAssistant Professor6000CS :00:00NULL 2KenAssistant Professor7000Med :00: :00:00 2KenProfessor8000Med :00:00NULL Table “emp” History table of “emp” UPDATE emp SET Title = ‘Assistant Professor’, Salary = 6000 WHERE EmpID = 1; HS_TYPE_emp::HS_HistoryBeginTime( 1, TIMESTAMP ‘ :00:00’);

25 At 2001/04/01 00:00:00, Ken was transferred to Med1 department. EmpIDEmpNameTitleSalaryDept 1TomAssistant Professor6000CS1 2KenProfessor8000Med1 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :00: :00:00 1TomAssistant5000CS :00: :00:00 1TomAssistant Professor6000CS :00:00NULL 2KenAssistant Professor7000Med :00: :00:00 2KenProfessor8000Med :00: :00:00 2KenProfessor8000Med :00:00NULL Table “emp” History table of “emp” UPDATE emp SET Dept = ‘Med1’ WHERE EmpID = 2; HS_TYPE_emp::HS_HistoryBeginTime( 2, TIMESTAMP ‘ :00:00’);

26 At 2002/04/01 00:00:00, Ken was transferred to Med3 department. EmpIDEmpNameTitleSalaryDept 1TomAssistant Professor6000CS1 2KenProfessor8000Med3 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :00: :00:00 1TomAssistant5000CS :00: :00:00 1TomAssistant Professor6000CS :00:00NULL 2KenAssistant Professor7000Med :00: :00:00 2KenProfessor8000Med :00: :00:00 2KenProfessor8000Med :00: :00:00 2KenProfessor8000Med :00:00NULL Table “emp” History table of “emp” UPDATE emp SET Dept = ‘Med3’ WHERE EmpID = 2; HS_TYPE_emp::HS_HistoryBeginTime( 2, TIMESTAMP ‘ :00:00’);

27 At 2003/04/01 00:00:00, Tom was transferred to CS2 department. EmpIDEmpNameTitleSalaryDept 1TomAssistant Professor6000CS2 2KenProfessor8000Med3 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :00: :00:00 1TomAssistant5000CS :00: :00:00 1TomAssistant Professor6000CS :00: :00:00 1TomAssistant Professor6000CS :00:00NULL 2KenAssistant Professor7000Med :00: :00:00 2KenProfessor8000Med :00: :00:00 2KenProfessor8000Med :00: :00:00 2KenProfessor8000Med :00:00NULL Table “emp” History table of “emp” UPDATE emp SET Dept = ‘CS2’ WHERE EmpID = 1; HS_TYPE_emp::HS_HistoryBeginTime( 1, TIMESTAMP ‘ :00:00’);

28 At 2004/04/01 00:00:00, Tom was transferred to another university. EmpIDEmpNameTitleSalaryDept 2KenProfessor8000Med3 EmpIDEmpNameTitleSalaryDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime 1TomAssistant4000CS :00: :00:00 1TomAssistant5000CS :00: :00:00 1TomAssistant Professor6000CS :00: :00:00 1TomAssistant Professor6000CS :00: :00:00 2KenAssistant Professor7000Med :00: :00:00 2KenProfessor8000Med :00: :00:00 2KenProfessor8000Med :00: :00:00 2KenProfessor8000Med :00:00NULL Table “emp” History table of “emp” DELETE FROM emp WHERE EmpID = 1; HS_TYPE_emp::HS_HistoryEndTime( 1, TIMESTAMP ‘ :00:00’);

29 Examples of Queries to History Table of “emp” How much is the salary of each employee on July 1, 2001? Who was an assistant professor on October 1, 2001? Who was an assistant professor from May 1, 2000 to February 1, 2003? Who belonged to the Med2 Department continuously for over 2 years? Who has the longest period as an assistant professor?

30 Example of SQL Query(1) How much is the salary of each employee on July 1, 2001? SELECT EmpName, Salary, HS_Hist FROM HS_TBL_emp WHERE HS_Hist.HS_Contains( TIMESTAMP' :00:00') EmpNameSalary HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime Tom :00: :00:00 Ken :00: :00:00 Answer:

31 Example of SQL Query(2) Who was an assistant professor on October 1, 2001? SELECT EmpName, Title, HS_Hist FROM HS_TBL_emp WHERE HS_Hist.HS_Contains( TIMESTAMP' :00:00') AND Title = 'Assistant Professor' EmpNameTitle HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime TomAssistant Professor :00: :00:00 Answer:

32 Example of SQL Query(3) Who was an assistant professor from May 1, 2000 to February 1, 2003? SELECT EmpName, Title, HS_Hist FROM HS_TBL_emp WHERE HS_Hist.HS_Overlaps( TIMESTAMP' :00:00', TIMESTAMP' :00:00') AND Title = 'Assistant Professor' EmpNameTitle HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime TomAssistant Professor :00: :00:00 Answer:

33 Example of SQL Query(4) Who belonged to the Med2 Department continuously for over 2 years? SELECT HT.EmpName, HT.Dept, HT.HS_Hist FROM TABLE(HS_TYPE_emp::HS_Period('Dept')) AS HT WHERE HT.Dept = 'Med2‘ AND HT.HS_Hist.HS_MonthInterval() >= INTERVAL '2' YEAR EmpNameDept HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime KenMed :00: :00:00 Answer:

34 Example of SQL Query(5) Who has the longest period as an assistant professor? SELECT HT1.EmpName, HT1.Title, HT1.HS_Hist FROM TABLE(HS_TYPE_emp::HS_Period('Title')) AS HT1 WHERE HT1.Title = 'Assistant Professor‘ AND HT1.HS_Hist.HS_MonthInterval() = ( SELECT MAX(HT2.HS_Hist.HS_MonthInterval()) FROM TABLE(HS_TYPE_emp::HS_Period('Title')) AS HT2 WHERE HT2.Title = 'Assistant Professor') EmpNameTitle HS_Hist HS_HistoryBeginTimeHS_HistoryEndTime TomAssistant Professor :00: :00:00 Answer: