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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3: Surviving Changes to <strong>Database</strong> ObjectsPhoneNumber ,CountryCode)SELECT 3 ,'Wayne' ,'Miller' ,'Regular' ,'(123)456-7890' ,'UK' ;Listing 3-4: Wayne Miller has the same phone number as Darrell Ling, but witha different country code.Our Stored procedure, however, is still working on the assumption that a customer canbe uniquely identified by their phone number alone. Since this assumption is no longervalid, the stored procedure, in its current form, could erroneously update more than onerow of data, as demonstrated in Listing 3-5.-- at this moment all customers have Regular statusEXEC dbo.SetCustomerStatus@PhoneNumber = '(123)456-7890',@Status = 'Preferred' ;-- the procedure has modified statuses of two customersSELECT CustomerId ,StatusFROM dbo.Customers ;CustomerId Status----------- -------------1 Preferred2 Regular3 PreferredListing 3-5: The unchanged stored procedure modifies two rows instead of one.81

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

Saved successfully!

Ooh no, something went wrong!