|
-
Jan 31st, 2011, 01:13 PM
#1
Thread Starter
New Member
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
IF EXISTS (SELECT ....)
BEGIN
INSERT
(...)
END
BEGIN
UPDATE(....)
END
Any ways to check for duplicated instead of updating it? Any examples?
-
Jan 31st, 2011, 01:50 PM
#2
Re: how to improve my ways of handling errors than avoiding it?
 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.
-
Feb 1st, 2011, 07:26 AM
#3
Re: how to improve my ways of handling errors than avoiding it?
Moved To Database Development
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|