how to improve my ways of handling errors than avoiding it?
Let say i insert a record in my database
New Record
CustomerID 1111 --> Inserted Successfully
Next record
CustomerID 2222 --> Duplicated CustomerID --> Should show duplicated.
Right now i am using
Quote:
IF EXISTS (SELECT ....)
BEGIN
INSERT
(...)
END
BEGIN
UPDATE(....)
END
Any ways to check for duplicated instead of updating it? Any examples?
Re: how to improve my ways of handling errors than avoiding it?
Quote:
Originally Posted by
MSIE
Let say i insert a record in my database
New Record
CustomerID 1111 --> Inserted Successfully
Next record
CustomerID 2222 --> Duplicated CustomerID --> Should show duplicated.
Right now i am using
Any ways to check for duplicated instead of updating it? Any examples?
With what you have shown it appears that CustomerID is not a primary auto incrementing field so the best method to ensure you are not inserting an exact match is to use a SELECT WHERE statement to the table to see if the CustomerID currently exists or not and from there continue with logic based on the results from the query i.e. show the current record for editing perhaps, indicate this would have been a duplicate etc.
Re: how to improve my ways of handling errors than avoiding it?
Moved To Database Development