I have a table has column ID,NAME which ID is PK I want to insert a new row if only this new row doesn’t exist in the table something like this :
if ID doesn't exist then INSERT STATEMENT HERE ; end if;
Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
hello albert,
as mr. sandeeptiwari mentioned on your question as comment you can use merge statement and here i will share with you sample example for merge and not exists with regular insert statement
first we need to create dummy table to test our code on it :
now we will using not exists clause with regular insert statement but with select like this :
now the result would be :
1 row created.
then trying to execute same statement again and check the result :
0 rows created.
that because the row is already exists before
now we will trying to do the same but in this time we will using merge statement :
now the result would be :
1 row merged.
then trying to execute same statement again and check the result :
0 row merged.
hope this help 🙂