Error handling

You can see there is a need for error handling by producing an error. The following code tries to insert an order and a detail row for this order:

EXEC dbo.InsertSimpleOrder 
 @OrderId = 6, @OrderDate = '20160706', @Customer = N'CustE'; 
EXEC dbo.InsertSimpleOrderDetail 
 @OrderId = 6, @ProductId = 2, @Quantity = 0; 

In SQL Server Management Studio, you can see that an error has happened. You should get a message that error 547 has occurred, that the INSERT statement conflicted with the CHECK constraint. If you remember, in order details, only rows where the value for the quantity is not equal to zero are allowed. The error occurred in the second statement, in the call of the procedure that inserts an order detail. The procedure ...

Get SQL Server 2017 Developer's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.