If i insert record in table A and these record should update in table B by using Trigger.How to achieve this.

Answer Posted / anil

CREATE table trg_tab
(ename VARCHAR(10),
sal NUMBER);
/
CREATE table log_tab
(usr VARCHAR(10),
upd DATE,
ename VARCHAR(10),
sal NUMBER
);
/
CREATE OR REPLACE TRIGGER log_trg
AFTER INSERT ON trg_tab
FOR EACH ROW
DECLARE
v_user VARCHAR(10);
BEGIN
SELECT USER
INTO v_user
FROm DUAL;
INSERT INTO log_tab
VALUES (v_user,SYSDATE,:NEW.ename,:NEW.sal);
END;
/
INSERT INTO trg_tab
SELECT ename,sal FROm emp;
/
SELECT * FROm log_tab;
/

Is This Answer Correct ?    7 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is sql scripting language?

526


What is data type in sql?

556


Why are indexes and views important to an organization?

527


what is 'mysqlshow'? : Sql dba

587


What are the three forms of normalization?

523






What does truncate mean in sql?

534


Can we insert delete data in view?

544


How do you use join?

524


Is grant a ddl statement?

453


Can I learn sql in a week?

551


What is rank () in sql?

532


Can you have a foreign key without a primary key?

510


What are the types of index in sql?

533


what is user defined functions? : Sql dba

546


What are the different type of joins in sql?

543