Sudantha
Sudantha

Reputation: 16204

SQL Server: halt an INSERT in a trigger

I have a trigger FOR INSERT and I need to stop the insertion by raising a error.

RAISERROR

will show the error message but is there is a way to halt the action any other method without transactions ?

Upvotes: 0

Views: 445

Answers (1)

RichardTheKiwi
RichardTheKiwi

Reputation: 107716

You have the trigger in the wrong place.

You need an INSTEAD OF trigger instead (no pun intended) to control it. A FOR INSERT trigger occurs AFTER the insert, so the horse has long bolted.

Upvotes: 5

Related Questions