Add value to a variable in the mysql table

Asked

Viewed 364 times

0

I have a Rigger, whenever a value is added to the table in mysql I take the old value(OLD) and add to another table, but I would like to improve this by adding the values to the same table but without duplicating, because I have 3 columns, ID, FIRST NAME, LAST NAME, if I do this the ID will be duplicated, there is some way to make the ID for example, ID+999?

 DELIMITER //

CREATE TRIGGER working
BEFORE UPDATE
   ON name FOR EACH ROW

BEGIN

INSERT INTO name
   ( id,
    name,
    adress)
   VALUES
   ( OLD.id+9999,
    OLD.name
    OLD.adress);

END; //

DELIMITER ;
  • I recommend that you put some code as you are doing or explain with some print what you want to do... Stack Overflow is not for this kind of doubt

  • I added Trigger’s code to make it better

  • I see no justification for such a procedure. Rethink your problem and analyze the best solution for it that does not seem to me, honestly, to be this.

1 answer

2


quite simple until...

update Table set field = field+100 Where id = xxx;

if the field value is 120, it will be 220.

  • Good afternoon Michel, thank you for the reply, would it work in the case of a Rigger? I added the code of the same so that it is better to view the problem

  • Yes, but you would have a big problem with the automatic indices of your table, you need to update the indices and risk having problems later with this

  • What kind of problem could occur in this case? Because of the doubts it would be better to add the old values to another table, right?

  • actually I did not understand why you do not update the record and keep the index, or create a control column itself and leave the index alone.

  • 1

    if Voce edits the index, all the relationship that the record has in other tables is lost, if vc is in index 11, 12, 13, 14, and adds thousand to 11, it will follow from 1012, 1013, and if you add 1000 aou 13, you will already find an index equal, that is, index is a thing for the bank to administer

  • Unfortunately I can not update the record because it receives the update precisely so that the first record is not viewed by other people, I need to think of some way to add the old value to the same table but without duplicating

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.