December 21, 2013 at 11:52 pm
Hello, I validate my trigger entries like this:
IF @Field = ''
BEGIN
ROLLBACK TRANSACTION GOTO E:
END
E:
E: is last line in my trigger and I have no code after that, I expected I can validate entries with this approach but instead after I go into E: it show me error message:
The transaction ended in the trigger. The batch has been aborted.
Can I ignore above message? Already tried TRY CATCH and it doesn't worked either.
___________________________________
Computer Enterprise Masoud Keshavarz
I don't care about hell.
If I go there I've played enough Diablo to know how to fight my way out.
December 22, 2013 at 12:33 am
I found this message:
The transaction ended in the trigger. The batch has been aborted.
Is because "ROLLBACK TRANSACTION".
If we don't want above message we have to remove "ROLLBACK TRANSACTION" and validate our entries outside of trigger.
___________________________________
Computer Enterprise Masoud Keshavarz
I don't care about hell.
If I go there I've played enough Diablo to know how to fight my way out.
December 22, 2013 at 12:44 am
Couple of things.
Can't you just use constraints?
Your posted code seems to assume that there will be just one row coming to trigger, which might not be the case.
December 22, 2013 at 12:51 am
Ville-Pekka Vahteala (12/22/2013)
Couple of things.Can't you just use constraints?
Your posted code seems to assume that there will be just one row coming to trigger, which might not be the case.
Well, if you insert 1000 rows all 1000 rows dont go to trigger at once
In fact your trigger execute 1000 times for each inserted rows 🙂
___________________________________
Computer Enterprise Masoud Keshavarz
I don't care about hell.
If I go there I've played enough Diablo to know how to fight my way out.
December 22, 2013 at 1:47 am
Ville-Pekka Vahteala (12/22/2013)
Couple of things.Can't you just use constraints?
Your posted code seems to assume that there will be just one row coming to trigger, which might not be the case.
Thank you, The insert trigger is called once for multiple row inserts 🙁
Im into big trouble
___________________________________
Computer Enterprise Masoud Keshavarz
I don't care about hell.
If I go there I've played enough Diablo to know how to fight my way out.
December 22, 2013 at 3:16 pm
masoudk1990 (12/22/2013)
Ville-Pekka Vahteala (12/22/2013)
Couple of things.Can't you just use constraints?
Your posted code seems to assume that there will be just one row coming to trigger, which might not be the case.
Thank you, The insert trigger is called once for multiple row inserts 🙁
Im into big trouble
No you're not. You can use an INSTEAD OF trigger to evaluate each row before you insert it into the table. A better way, of course, is to prevalidate things before you even try an INSERT. Look it up in "Books Online" (get there by pressing the {f1} key when you're in SSMS).
Of course, I can't see your code. If you were to post it, perhaps we'd be better able to assist.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply