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

Answer Posted / abhishekjaiswal

Table 1(u_register) Parent table
 Name                                      Null?                           Type
 ----------------------------------------- -------- ----------------------
 FIRST_NAME                                                             VARCHAR2(15)
 LAST_NAME                           NOT NULL                  VARCHAR2(15)
 DOB                                       NOT NULL                   DATE
 USER_NAME                           NOT NULL                 VARCHAR2(15)
 NEW_PASSWORD                   NOT NULL                 VARCHAR2(15)
 CONFIRM_PASSWORD           NOT NULL                 VARCHAR2(15)
 U_ID                                        NOT NULL                 NUMBER

table 2(login_detail) Child table
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------
 ID                                        NOT NULL NUMBER
 USER_NAME                                          VARCHAR2(15)
 NEW_PASSWORD                                       VARCHAR2(15)

Now we will create trigger to insert column 'user_name','new_password' of u_register into column 'USER_NAME ','NEW_PASSWORD' of login_detail.We will use after insert trigger as 

create or replace 
trigger tgr_login
after insert on u_register
for each row
begin 
insert into login_detail
values (:new.u_id,:new.user_name,:new.new_password);
end tgr_login;

It will work for sure.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many unique keys can a table have?

555


what is 'trigger' in sql? : Sql dba

558


Is json a nosql?

541


how would concatenate strings in mysql? : Sql dba

572


how to include numeric values in sql statements? : Sql dba

558






What does sql stand for?

543


what are myisam tables? : Sql dba

552


what is innodb? : Sql dba

576


Can we join two tables without common column?

513


What are joins in sql?

538


What is mutating table error?

663


What is trigger in sql?

581


how many triggers are allowed in mysql table? : Sql dba

559


Do prepared statements prevent sql injection?

528


How do you rename a table in sql?

534