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 4: When Upgrading Breaks CodeVALUES ( 1 ,'Road Construction on Rt 59' ,'Lynn Lewis' ,0) ;Listing 4-22: The FrontPageArticles table, with test data.The MERGE command shown in Listing 4-23 will update the existing article and inserta new one.MERGE dbo.FrontPageArticles AS targetUSING( SELECT 1 AS ArticleID ,'Road Construction on Rt 53' AS TitleUNION ALLSELECT 2 AS ArticleID ,'Residents are reaching out' AS Title) AS source ( ArticleID, Title )ON ( target.ArticleID = source.ArticleID )WHEN MATCHEDTHEN UPDATESET Title = source.TitleWHEN NOT MATCHEDTHEN INSERT(ArticleID ,Title ,NumberOfViews)VALUES ( source.ArticleID ,source.Title ,0) ;SELECT ArticleID ,Title ,NumberOfViews124

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

Saved successfully!

Ooh no, something went wrong!