I have a try catch in my physical C# code that just skips this insert process when a error accrues and continues the loop to fill the database. However this is bad coding practice.
So I would like to add an IF
statement to the stored procedure below that will just skip if a primary key is already there. My primary key is @id
.
How can I go about this?
CREATE PROCEDURE InsertProc
(
@id int,
@to nvarchar(100),
@from nvarchar(100),
@subject nvarchar(100),
@date datetime
)
AS
INSERT INTO Emails_Log (Email_ID, e_To, e_From, e_Subject, e_Date)
VALUES (@id, @to, @from, @subject, @date)