I want to verify the existence of a record before inserting it into the database. My objective is:
1.- Verify the existence, if it exists. Then return a message that says "Not inserted, because it already exists"
2.- Otherwise, insert it. And return a message that says: "Record inserted"
All of the above in a single stored procedure. Here's what I have next: Table named: actors Fields: Name Varchar(50), FBirth DateTime, LBirth Varchar(50), Nationality Varchar(50), FDeath DateTime, LDeath Varchar(50), IN values are the previous fields. The OUT is: Insert Varchar(50)
SP URL: https://drive.google.com/file/d/1ceKN8rV-9s8qr39oTvozx4iDLVh9NUtR/view?usp=sharing
It tells me that there is an error in or near the "IF R" and also in the "SET Insert" in both. Could someone please tell me how it should be?
Thanks and regards.
Note: I offer an apology. I had a strong migraine when I wrote that question.
From this dataset:
This stored procedure performs the function you describe:
Returning Record inserted in the first call and Not inserted, because it already exists in the second:
I understand that you do this because, by defining a unique key, the
id_actor
would still be incremented by duplicate inserts, despite not being able to perform them.Leave me any questions in the comments.