Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I write this trigger?

Status
Not open for further replies.

rarrington

Programmer
Dec 20, 2007
1
US

Hey Everyone…

I’ve been searching all over for the answer to this one. If you have the answer, it would help me out a lot!

Using MySQL triggers, I want to sync content between two tables; I have table “user” and table “users”, each have similar columns “last_name” “first_name” “user_id” …etc, and when a row gets written to table “users”, I wanted that record to be replicated and inserted to “user” (with all the same field info).

How do I write this trigger? I know, it’s anti-normalization, but it will really help me out with testing one of our site's authentication.

Thanks all!
 
Couldn't you use from the DB or from PHP substr()(I am a php user!)
First decide which table will be the "master one"
do a substr per row you need to dupe from the master
then do the same from the "slave"
if sub1 !=sub2 then its an update
 
delimiter $$

drop trigger if exists mydb.rep_user $$
create trigger mydb.rep_user before insert on mydb.users
for each row begin
insert into mydb.user set last_name=new.last_name, first_name=new.first_name user_id=new.user_id;
end$$

delimiter ;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top