I would like to write an automatic journal for my table 'booking', which logs every insert, update and delete.
The (simplified) table 'booking' looks like this:
and the 'bookingjournal' I would like to create looks like this:
Let's say my application makes the following operations on the table 'booking':
I would like the 'bookingjournal' to have the following entries:
What would be the simplest solution for achieving this? Trigger? PL/SQL-Script? And could someone possibly show me the pieces of code I need?
Any help is greatly appreciated.
Olel
The (simplified) table 'booking' looks like this:
Code:
CREATE TABLE "BOOKING"
(
ID bigint PRIMARY KEY NOT NULL,
VERSION bigint NOT NULL,
CUSTOMER_ID bigint NOT NULL,
TEXT varchar(255)
)
Code:
CREATE TABLE "BOOKINGJOURNAL"
(
ID bigint PRIMARY KEY NOT NULL,
VERSION bigint NOT NULL,
CUSTOMER_ID bigint NOT NULL,
TEXT varchar(255),
OPERATION varchar(255)
)
Code:
INSERT INTO BOOKING VALUES(1, 0, 42, 'Booking of customer 42.');
INSERT INTO BOOKING VALUES(2, 0, 43, 'Booking of customer 43.');
UPDATE BOOKING SET (TEXT, VERSION) = ('Changed booking of customer 42.', 1) WHERE ID = 1;
UPDATE BOOKING SET (TEXT, VERSION) = ('Changed booking of customer 43.', 1) WHERE ID = 2;
DELETE FROM BOOKING WHERE ID = 2;
Code:
ID, VERSION, CUSTOMER_ID, TEXT, OPERATION
1, 0, 42, 'Booking of customer 42.', 'INSERT'
2, 0, 43, 'Booking of customer 43.', 'INSERT'
1, 1, 42, 'Changed booking of customer 42.', 'UPDATE'
2, 1, 43, 'Changed booking of customer 43.', 'UPDATE'
2, 1, 43, 'Changed booking of customer 43.', 'DELETE'
Any help is greatly appreciated.
Olel