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 1: Basic <strong>Defensive</strong> <strong>Database</strong> <strong>Programming</strong> TechniquesNow, let's populate each table with some sample data, as shown in Listing 1-22.DELETE FROM dbo.Codes ;INSERT INTO dbo.Codes( Code ,Description)SELECT 'AR' ,'Old description for Arkansas'UNION ALLSELECT 'IN' ,'Old description for Indiana' ;DELETE FROM dbo.CodesStaging ;INSERT INTO dbo.CodesStaging( Code ,Description)SELECT 'AR' ,'description for Argentina'UNION ALLSELECT 'AR' ,'new description for Arkansas'UNION ALLSELECT 'IN' ,'new description for Indiana ' ;Listing 1-22: Populating the Codes and CodesStaging tables.Now, we'll examine two different ways of updating data in the permanent table, basedon data in the staging table, both of which are subject to ambiguities if care is not taken.1. Using UPDATE…FROM.2. Updating an inline view.We'll then discuss strategies for avoiding such ambiguities.46

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

Saved successfully!

Ooh no, something went wrong!