Returning Procedure Status

So far we have been writing very optimistic code: only a little error checking and very few validations. Unfortunately, there's plenty that could go wrong here.

Let's look closely at the prAddItemToCart procedure we just finished writing. If something goes wrong, we shouldn't insert an order, and the user or her application should be warned. What if we couldn't access the default unit price because of database problems, network problems, and so forth? You can't insert an order without a price. All these circumstances are handled with the procedure return status.

The procedure return status describes the state of the procedure when it ended. It tells the calling program why the procedure stopped executing.

Under ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.