0

I have two tables (A & B). I want to duplicate a row from Table A to Table B when a value of a column in Table A is equal to x, how would I do that using a trigger? Table A is constantly updating, via query in my vb.net program, until such time that a column in Table A equals to x, I want to copy that row into Table B, not via another query on vb.net but via mysql database trigger. Any input would be appreciated.

Thanks

1 Answer 1

1

This works for mySQL. I've tried it out.

CREATE TRIGGER `tableA_AUPD` AFTER UPDATE ON `tbla` FOR EACH ROW
begin   
    IF (NEW.fldx = 'x') THEN
        INSERT INTO tblb (fldb0,fldb1,fldx) VALUES(NEW.flda0,NEW.flda1,NEW.fldx);
    END IF;
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.