Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

mysql stored procedure insert if not exists

DELIMITER //

CREATE PROCEDURE `intoBooksQty`(`newcallNumber` VARCHAR(10))
BEGIN
  INSERT INTO `bookqty` (`callNumber`, `bookQty`, `bookqtyOut`)
  SELECT `newcallNumber`, 1, 0
  FROM `books`
  WHERE `callNumber` = `newcallNumber`
    ON DUPLICATE KEY UPDATE `bookQty` = `bookQty` + 1;
END//

DELIMITER ;
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mysql #stored #procedure #insert #exists
ADD COMMENT
Topic
Name
4+6 =