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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Custom Error msg

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-25 : 08:15:53
Vasi writes "How to generate custom erro msg.
I wish to check in my trigger whether inserted or updated row has unique column value. If not, generate a custom msg and abort trigger without inserting. It tried using RAISERROR and ROLLBACK like this:

CREATE TRIGGER on TABLE1
upon INSERT
AS
IF EXISTS(select column_ID inserted.column_id =table1.column_id)
BEGIN
RAISERROR (',,,,', 16,1)
ROLLBACK
END
ELSE
BEGIN
insert into tabel1..
...
END

-----
my client app brings up DB error msg and subsequently a runtime error. I think ROLLBACK is necessary.

should I change severity level?
I want my code to bring up a custom-error msg and prevent inserting row into the table, when above condition is met."

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-25 : 08:46:41
See If these are helpful
http://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -