1

i have a table which contains columns as "barkoda1,barkoda2,barkoda3,@pdfa1,@pdfa2,@pdfa3", what i'm trying to do is when a record assigned to barkoda1 copy same record to @pdfa1,for example if barkoda1 defined as "1234567890" @pdfa1 should be "1234567890.pdf".

i tried to create a trigger for it, but failed;

DELIMITER //
CREATE TRIGGER pdfdeneme AFTER INSERT
ON finyeb_ba_2369_bio_for_2__r_d_
FOR EACH ROW
BEGIN
  UPDATE finyeb_ba_2369_bio_for_2__r_d_ SET `@pdfa1`=NEW.barkoda1;
END//
DELIMITER ;

when i create this trigger,it doesn't return any error but when i add record to table mysql returns "it is already used by statement which invoked this stored function/trigger".

also tried this way

DELIMITER //
CREATE TRIGGER pdfdeneme BEFORE INSERT
ON finyeb_ba_2369_bio_for_2__r_d_
FOR EACH ROW
BEGIN
  INSERT INTO finyeb_ba_2369_bio_for_2__r_d_(`@pdfa1`) VALUES(NEW.barkoda1);
END//
DELIMITER ;

But same error happened, what am i doing wrong here?

2
  • You only need the set part of the statement..with a concat for the .pdf part Commented Oct 8, 2020 at 14:36
  • @P.Salmon oh you are right Commented Oct 8, 2020 at 15:58

1 Answer 1

1

You need a BEFORE INSERT TRIGGER

And then only use the SET Clause

DELIMITER //
CREATE TRIGGER pdfdeneme BEFORE INSERT
ON finyeb_ba_2369_bio_for_2__r_d_
FOR EACH ROW
BEGIN
  SET NEW.`@pdfa1` =  CONCAT(NEW.barkoda1,'.pdf');
END//
DELIMITER ;

But your column name is a bad choice, it leads on the first glance to false conclusions.

Sign up to request clarification or add additional context in comments.

1 Comment

you are right about column name,unfortunately it's not my design,i need to continue over it and that column names causing problem all the time, thanks for your help.

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.