17.07.2015 Views

Defensive Database Programming - Red Gate Software

Defensive Database Programming - Red Gate Software

Defensive Database Programming - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3: Surviving Changes to <strong>Database</strong> ObjectsASBEGIN ;SELECT CustomerId ,FirstName ,LastName ,PhoneNumber ,StatusFROM dbo.CustomersWHERE FirstName = COALESCE (@FirstName, FirstName)AND LastName = COALESCE (@LastName,LastName)AND PhoneNumber = COALESCE (@PhoneNumber,PhoneNumber) ;END ;GOListing 3-15: The modified SelectCustomersByName stored procedure includes anadditional FirstName parameter.As a result of this modification, the two ways of invoking the stored procedure are nolonger equivalent. Of course, we will not receive any error message; we will just silentlystart getting different results, as shown in Listing 3-16.-- in the new context this call is interpreted-- differently. It will return no rowsEXEC dbo.SelectCustomersByName'Hansen',-- @FirstName'(234)123-4567' ; -- @LastName-- this stored procedure call is equivalent-- to the previous oneEXEC dbo.SelectCustomersByName@FirstName = 'Hansen',@LastName = '(234)123-4567' ;90

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!