![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
I prefer to have the one trigger instead of two nearly-identical triggers. That is why I have @AccessType. Good or bad? Is there a better way of determining between insert and update? |
|
What sort of error handling should I have? While this code does work for multiple rows, I need a handling for if one or more inserts/updates fail, and it should be something that returns reasonable detail to the application. |
|
declare #Inserted insensitive cursor |
|
open #Inserted fetch next from #Inserted into @ACUK,@ACOrd,@ACName,@ACNr while @@fetch_status=0 |
#3
| ||||
| ||||
|
|
Gene Wirchenko (genew (AT) ocis (DOT) net) writes: I prefer to have the one trigger instead of two nearly-identical triggers. That is why I have @AccessType. Good or bad? Is there a better way of determining between insert and update? You are on the right track, but this is better: IF exists (SELECT * FROM deleted) No need to actually count the rows! |
|
What sort of error handling should I have? While this code does work for multiple rows, I need a handling for if one or more inserts/updates fail, and it should be something that returns reasonable detail to the application. By default when you are in a trigger, the first error will abort the batch and rollback the transaction. |
|
The default is global which means that the cursor still exists. Which can cause nasty surprises next time. In fact, I would expect this to happen to you, because you only have CLOSE at the end. You need DEALLOCATE instead. With CLOSE the cursor still exists. # in the beginning of the cursor name is a little odd. |
|
WHILE 1 = 1 BEGIN FETCH cur ... IF @@fetch_status <> 0 BREAK Then you only need FETCH statement, and one less line to change if you add one more column to the cursor. |
#4
| |||
| |||
|
|
I was thinking it would then be temporary. Does that not work with cursors? |
![]() |
| Thread Tools | |
| Display Modes | |
| |