How to throw custom T-SQL exception?

3

I have a tigger for CPF validation, and I want to throw an exception if the entered CPF is invalid.

About throwing exceptions I've been reading this #

But what I want is to throw a new exception, an exception that does not exist in the system, type, a CpfInvalid exception.

    
asked by anonymous 26.06.2016 / 16:30

1 answer

2

Matheus, SQL SERVER does not have a function for validation of CPF or CNPJ , these types of numbers are Brazilian standards and are not applied to other countries, such a function would have no use for many users of that database.

You have the option to throw the exception through BEGIN TRY END TRY or use the RAISERROR to return an error message.

The ideal in this case is that you treat your client-side validation (EX, JavaScript) and application (EX, C #, JAVA), do not use the database for this type of validation, this has a cost of processing back and forth to the bank, when your application could easily validate.

    
26.06.2016 / 22:00