0

Most of the posts I found involve using PHP but I am not using PHP in my case. Here is my MySQL procedure

CREATE DEFINER=`root`@`localhost` PROCEDURE `create_email`(in UID_ int(20),
                                in user_id_ int(20),
                                in from_email_ VARCHAR(1024), 
                                in subject_email_ TINYTEXT, 
                                in body_email_ LONGTEXT, 
                                out id_ BIGINT(20) unsigned )
BEGIN
    set id_=0;
    INSERT INTO emails (UID, user_id, from_email, subject_email, body_email)
    VALUES
        (UID_ ,user_id_, from_email_, subject_email_, body_email_);
    set id_ = LAST_INSERT_ID();
END

Currently my procedure does not check if the data in the table exists it only inserts as the data is being received. What is an effective way of making sure incoming email data does not dublicate onto my emails table?

Thank you in advance.

  • 1
    You should create a unique index across the columns that should be unique for the table. Let MySQL handle the error handling. – Goodbye StackExchange Oct 08 '18 at 21:07
  • Hi. Best remove the workbench tag as this isn't a workbench problem. There is lots on this sort of requirement here: https://stackoverflow.com/questions/1361340/how-to-insert-if-not-exists-in-mysql – MandyShaw Oct 08 '18 at 21:09
  • @FrankerZ I guess I wasn't clear enough. I am pulling emails from different IMAP servers so I can't set my UID column to Unique Index since I can have emails from different servers using the same UID – Francisco Ochoa Oct 09 '18 at 01:01

0 Answers0