How to check in a stored proc if data is already present?
I have a stored proc like the following. It works on a table called
ProductType with only one field, called ProductTypeName.
DROP PROCEDURE IF EXISTS myDB.setProductType;
CREATE PROCEDURE myDB.`setProductType`(
IN ProductType VARCHAR(20))
BEGIN
INSERT INTO ProductType
(
ProductTypeName
)
VALUES
(
ProductTypeName );
END;
It works fine, but I would like to avoid duplicates. How can I make
the stored proc check if that ProductTypeName is already in the table,
and only insert it if it's not? Thanks.
|