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

What does trigger mean in slang?

730


What is pl sql script?

728


Do we need to create index on primary key?

638


Why do we create stored procedures & functions in pl/sql and how are they different?

692


What is trigger types of trigger?

718






how to increment dates by 1 in mysql? : Sql dba

722


What do you mean by stored procedures?

732


Is there a pl/sql pragma similar to deterministic, but for the scope of one single sql select?

751


How does left join work in sql?

700


How is debugging done?

721


If i can use sys.check_constraints to display my constraints from my database using sql server 2005, how can i display then if i am using sql server 2000????

3697


What is a database trigger?

789


Why do we need unique key in a table?

673


What does (+) mean in sql joins?

736


Can we use delete in merge statement?

730