Friday, March 23, 2012

how to throw Custom Error instead of Default SQL Server Error

Hi guys!
i've very basic knowledge of DB as i'm a software developer i dont know
much about the DB other then writing Queries.
now, the problem is, i'm in a situation, where i need to throw a custom
error whenever some specific error occure while deleting the record
from the table.
the Scenrio is, like this:
i've table that has refencial intigrity constraint. it disallow to
delete the parent row if it is refered in the child table twice. this
is prefectly alright. all i want to do is, whenever such situation
occurs i want to throw my custom error instead of the sql server's
default error msg.
any idea,suggestion are most welcome.
Database : Sql Server 2000
thanks,
Lucky
If you are using the insert statement within a stored procedure, you
can use the @.@.ERROR variable and RAISERROR with your custom message.
Regards
Manisha Gandhi
lucky wrote:
> Hi guys!
> i've very basic knowledge of DB as i'm a software developer i dont know
> much about the DB other then writing Queries.
> now, the problem is, i'm in a situation, where i need to throw a custom
> error whenever some specific error occure while deleting the record
> from the table.
> the Scenrio is, like this:
> i've table that has refencial intigrity constraint. it disallow to
> delete the parent row if it is refered in the child table twice. this
> is prefectly alright. all i want to do is, whenever such situation
> occurs i want to throw my custom error instead of the sql server's
> default error msg.
> any idea,suggestion are most welcome.
> Database : Sql Server 2000
> thanks,
> Lucky
|||thanks for your replay,
but the situation is, after i implemented, what u suggested, now it
throws 2 errors. one is my custom error and another is default SQL
Server error.
how can i stop sql server to throw it's own an error?
Lucky
|||You cannot prevent a raised error from being returned to the client in SQL
2000. SQL 2005 provides a try/catch construct that can meet your
requirement.
Hope this helps.
Dan Guzman
SQL Server MVP
"lucky" <tushar.n.patel@.gmail.com> wrote in message
news:1164629710.750116.166010@.f16g2000cwb.googlegr oups.com...
> thanks for your replay,
> but the situation is, after i implemented, what u suggested, now it
> throws 2 errors. one is my custom error and another is default SQL
> Server error.
> how can i stop sql server to throw it's own an error?
> Lucky
>
sql

No comments:

Post a Comment