create table pssst.gehaltsdaten (userid integer not null, gehalt decimal(9,0) not null, sys_start timestamp(12) not null generated always as row begin, sys_end timestamp(12) not null generated always as row end, trans_id timestamp(12) generated always as transaction start id, period system_time(sys_start,sys_end)) in dbperso.tsgehalt ; |
alter table pssst.gehaltsdaten add sys_start timestamp(12) not null generated always as row begin; alter table pssst.gehaltsdaten add sys_end timestamp(12) not null generated always as row end; alter table pssst.gehaltsdaten add trans_id timestamp(12) generated always as transaction start id; alter table pssst.gehaltsdaten add period system_time(sys_start,sys_end) ; |
Create table pssst.gehaltsdaten_hist LIKE pssst.gehaltsdaten IN dbperso.higehalt ; |
alter table pssst.gehaltsdaten add versioning use history table pssst.gehaltsdaten_hist; |
insert into pssst.gehaltsdaten ( userid,gehalt ) values (1 , 75000. ) ; insert into pssst.gehaltsdaten ( userid,gehalt ) values (2 , 72000. ) ; commit; insert into pssst.gehaltsdaten ( userid,gehalt ) values (3 ,125000. ) ; insert into pssst.gehaltsdaten ( userid,gehalt ) values (4 , 85000. ) ; |
USERID | GEHALT | SYS_START | SYS_END | TRANS_ID |
1 | 75000. | 2013-10-09-10.11.42.621277189000 | 9999-12-30-00.00.00.000000000000 | <null> |
2 | 72000. | 2013-10-09-10.11.42.621277189000 | 9999-12-30-00.00.00.000000000000 | <null> |
3 | 125000. | 2013-10-09-10.11.42.626137159000 | 9999-12-30-00.00.00.000000000000 | <null> |
4 | 85000. | 2013-10-09-10.11.42.626137159000 | 9999-12-30-00.00.00.000000000000 | <null> |
update pssst.gehaltsdaten set gehalt = gehalt + 2000 where userid = 1 ; |
USERID | GEHALT | SYS_START | SYS_END | TRANS_ID |
1 | 77000. | 2014-10-09-10.21.38.370295502000 | 9999-12-30-00.00.00.000000000000 | <null> |
2 | 72000. | 2013-10-09-10.11.42.621277189000 | 9999-12-30-00.00.00.000000000000 | <null> |
3 | 125000. | 2013-10-09-10.11.42.626137159000 | 9999-12-30-00.00.00.000000000000 | <null> |
4 | 85000. | 2013-10-09-10.11.42.626137159000 | 9999-12-30-00.00.00.000000000000 | <null> |
USERID | GEHALT | SYS_START | SYS_END | TRANS_ID |
1 | 75000. | 2013-10-09-10.11.42.621277189000 | 2014-10-09-10.21.38.370295502000 | <null> |
delete from pssst.gehaltsdaten where userid = 4 ; |
USERID | GEHALT | SYS_START | SYS_END | TRANS_ID |
1 | 77000. | 2014-10-09-10.21.38.370295502000 | 9999-12-30-00.00.00.000000000000 | <null> |
2 | 72000. | 2013-10-09-10.11.42.621277189000 | 9999-12-30-00.00.00.000000000000 | <null> |
3 | 125000. | 2013-10-09-10.11.42.626137159000 | 9999-12-30-00.00.00.000000000000 | <null> |
USERID | GEHALT | SYS_START | SYS_END | TRANS_ID |
1 | 75000. | 2013-10-09-10.11.42.621277189000 | 2014-10-09-10.21.38.370295502000 | <null> |
4 | 85000. | 2013-10-09-10.11.42.626137159000 | 2014-12-09-13.35.45.986872876000 | <null> |
FOR SYSTEM_TIME AS OF <timestamp> |
select * from pssst.gehaltsdaten FOR SYSTEM_TIME AS OF timestamp('01.01.2014') ; |
USERID | GEHALT | SYS_START | SYS_END | TRANS_ID |
2 | 72000. | 2013-10-09-10.11.42.621277189000 | 9999-12-30-00.00.00.000000000000 | <null> |
3 | 125000. | 2013-10-09-10.11.42.626137159000 | 9999-12-30-00.00.00.000000000000 | <null> |
1 | 75000. | 2013-10-09-10.11.42.621277189000 | 2014-10-09-10.21.38.370295502000 | <null> |
4 | 85000. | 2013-10-09-10.11.42.626137159000 | 2014-12-09-13.35.45.986872876000 | <null> |
with daten2013 as ( select userid,gehalt from pssst.gehaltsdaten FOR SYSTEM_TIME AS OF '2013-12-31-00.00.00.000000000000' ) , daten2014 as ( select userid,gehalt from pssst.gehaltsdaten FOR SYSTEM_TIME AS OF TIMESTAMP('31.12.2014') ) select ifnull (daten2013.userid,daten2014.userid) as userid, daten2013.gehalt as "Gehalt 2013" , daten2014.gehalt as "Gehalt 2014" from daten2013 full join daten2014 on daten2013.userid = daten2014.userid ; |
USERID | Gehalt 2013 | Gehalt 2014 |
1 | 75000. | 77000. |
2 | 72000. | 72000. |
3 | 125000. | 125000. |
4 | 85000. | <null> |
create trigger triggername no cascade before insert on schema.tabelle_hist referencing new as n for each row mode db2sql begin atomic set n.aenderId = current sqlid ; end |
Zurück zu DB2 | Home | Impressum / Datenschutz |