How to do a procedure stored in mysql that allows to validate if a repeated data is found and if so to be able to register in two related tables otherwise insert only the id in a table?
I have the following SQL script works if cc is not found in the database and inserted into the two tables but if the cc variable is in the DB it does not work Thank you ..
DROP PROCEDURE IF EXISTS 'owners_add';
DELIMITER $$
CREATE PROCEDURE owners_add(
IN '@name' varchar(35),
IN '@last' varchar(35),
IN '@cc' int(12),
IN '@cell_phone' varchar(15))
BEGIN
DECLARE id_people INT DEFAULT 0;
SET id_people=(SELECT id FROM people WHERE cc=@cc);
IF(id_people IS NULL) THEN
INSERT INTO people(name,last,cc,cell_phone)
VALUES('@name','@last','@cc','@cell_phone');
SET @ID = LAST_INSERT_ID();
INSERT INTO owners(id) VALUES(@ID);
ELSE
INSERT INTO owners(id) VALUES(id_people);
END IF;
END $$