What can a ‘database trigger’ be used for? Explain concisely what the code below does.

What will be an ideal response?


CREATE TRIGGER st_customer_trg BEFORE INSERT OR UPDATE ON st_customer
FOR EACH ROW
BEGIN
IF :old.customer_insert_user IS NULL THEN
:new.customer_insert_user := USER;
:new.customer_insert_date := SYSDATE;
:new.customer_update_user := NULL;
:new.customer_update_date := NULL;
ELSE
:new.customer_insert_user := :old.customer_insert_user;
:new.customer_insert_date := :old.customer_insert_date;
:new.customer_update_user := USER;
:new.customer_update_date := SYSDATE;
END IF;
END;

A database trigger is a stored procedure that Oracle invokes ("fires") automatically when certain events occur, for example, when a DML operation modifies a certain table. Triggers enforce business rules, prevent incorrect values from being stored, and reduce the need to perform checking and cleanup operations in each application. The above trigger fires before insert or update on st_customer. If the field customer_insert_user of the row in question is empty, USER, SYSDATE etc are inserted, otherwise original data is kept.

Computer Science & Information Technology

You might also like to view...

Determine the source and destination addresses in the Ethernet and IP headers for the ICMP Echo Request messages that were captured at PC1.

What will be an ideal response?

Computer Science & Information Technology

Any of the file systems supported by Windows 7 and Windows 8.1 are suitable for installation

Indicate whether the statement is true or false

Computer Science & Information Technology

The ________ is the central node that coordinates the flow of data by sending messages directly between the sender and receiver nodes.

A. client B. switch C. server D. gateway

Computer Science & Information Technology

Briefly describe DES and its variants.

What will be an ideal response?

Computer Science & Information Technology