Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ugh3012
Yak Posting Veteran
62 Posts |
Posted - 2014-06-27 : 14:40:52
|
I have a simple update statement that will update one field, and that field is part of the primary key. During the update process, some of the rows will cause duplicate error. Is there a way to update the table and suppress the error? What I am looking for is a way to update the records that it can and ignore those it cannot. Right now, the entire process is terminated if duplicate error occurs. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-06-27 : 15:16:56
|
You will need to modify your update statement to exclude the records that should not be updated, for example like shown below. I am assuming that the PK is a composite key consisting of pkColumn1, pkColumn2 and pkColum3 and I am trying to update pkColumn3 with somevalue without causing PK violations.UPDATE a SET a.pkColumn3 = 'somevalue'FROM TableA aWHERE NOT EXISTS( SELECT * FROM tableA b WHERE a.pkColumn1 = b.pkColumn1 AND a.pkColumn2 = b.pkColumn2 AND 'somevalue' = b.pkColumn3); |
|
|
sardam98
Starting Member
10 Posts |
Posted - 2014-06-29 : 03:46:49
|
thank youhttp://www.soran.edu.iq |
|
|
|
|
|