jevie jevie - 8 days ago 5
SQL Question

SQL Error Message in the Exception as User Defined Error Message

I have a table with the following design:

tbl_property
Fields: property_id(Primary Key),property_name and fpp_id(Foreign Key From another Table tbl_fpp)

tbl_fpp
Fields: fpp_id(primary_key),fpp_name


I have Rows inserted to both tables.

Every time I insert in the
tbl_property
I also get the
fpp_id
from another table.

I wanted to throw an exception to the User in my Visual Basic Application that if I delete a
table_fpp
record, if that record is used/referenced in the
tbl_property
then I will prompt the user a message like. "You cannot delete an FPP because it is used in other record." Else it will delete the record of
table_fpp
if it is not referenced?

Answer
RAISERROR (N' You cannot delete an FPP because it is used in other record.' , -- Message text.
       10, -- Severity,
       1, -- State)

You can find more detail here http://msdn.microsoft.com/en-us/library/ms178592.aspx