I am trying to write a stored procedure that checks if a value exist, and if it does not, it will insert it. The problem I am having is it nots stroing. The schema for this procedure is tag_id VARCHAR(24) primary key and tag varchar(255)
Create the Procedure
DELIMITER //
CREATE PROCEDURE `create_tag_not_exist` (IN tag_id VARCHAR(24), IN tag VARCHAR(255))
BEGIN
IF(SELECT COUNT(*) FROM tags WHERE tag_id = tag_id <= 0 ) THEN
INSERT INTO tags(tag_id, tag) VALUES (tag_id, tag);
END IF;
END //
Insert data into it
call create_tag_not_exist('abc123', 'doeraeme');
Yet the table is still empty. Am I doing something wrong?
Try this
I changed the parameter name from Tag_id to TagID to prevent confusion in the field name and parameter name.