I am designing a Database.
I want to ensure all validations happen at the client and also at the server end.
Now I am looking at the server side validations.
The best place to put them were in Rules/Constraints.
But the problem that I face is that I am unable to raise a user-defined error message when data violating a rule is entered.
For example, I have a unique constraint on the Name column of a Table.
Now only place this can be validated is on the server.
However I am unable to trap the error and do a raiserror of my own.
The only place I am able to do it is in an
Insert/Update Triggger on that table.
Here I have to validate all the data myself.
And raise the specific error and roll back the Transcation.
However this means that the row is inserted and then the rollback takes place.
Unlike in a Unique constraint where the data is validated before it is inserted.
So the basic question is can I bind the constraint to a user Defined message so that every time a violation of a rule happens a specific error is raised?