Procedure is only running the first part, why?

Asked

Viewed 50 times

0

Good afternoon, I have two tables, one table tb_addresses with attributes

idaddress int(11), idperson int(11), desaddres varchar(128), descomplement varchar(128)

And there is a primary key of the table tb_persons, and a table tb_persons with attributes idperson, desperson

I created a trial like this :

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_addresses_save`(

pidaddress int(11), 
pidperson  int(11), 
pdesaddress VARCHAR(128), 
pdescomplement VARCHAR(32), 




)
BEGIN

    DECLARE vidperson INT(11);

    INSERT INTO tb_persons (desperson)
    VALUES('AAAA');

    SET vidperson = LAST_INSERT_ID();

    INSERT INTO tb_addressses (idperson, desaddress, descomplement)
    VALUES(vidperson,'Meu endereco','Descomplement');

    SELECT * FROM tb_addresses a INNER JOIN tb_persons b USING(idperson) WHERE a.idaddress = LAST_INSERT_ID();

END

However, when I will run the trial, only the first insert is made, in the case of Persons, the insert address does not occur, why is only a part of the Procedure occurring? I’ve been researching but this came up:

Cannot add or update a Child Row: a Foreign key Constraint fails

But I don’t understand, if there already is one idperson set in the table tb_address, in case the last_insert_id(), because you keep making that mistake?

  • Your field list is syntactically wrong since you start it with a ,.

  • No, there it was because I copied and pasted here, but in the tests here it did not have the n comma, and then it gave error

  • It seems that the problem is here: LAST_INSERT_ID(); where you look for this value?

No answers

Browser other questions tagged

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