SQL Server – Impact of Raiserror on Stored Procedure Performance

sql serverstored-procedures

Does RAISERROR in a SQL Server stored procedure affect performance?

Would I be better off just having a try-catch wrapper around the whole procedure and just catch the errors in the database access layer?

Right now for logging in a user, I check if the user exists and RAISERROR if the user does not exist. Would I better just let the procedure return null and interpret that in the database access layer?

Best Answer

I would not worry about performance in this situation.
I would go with raising an error for 2 reasons:

  1. You quit earlier (when you find out user does not exist), and make a clear message.
  2. IMHO raising an error is more readable and makes your code clearer.