+ All Categories
Home > Business > Merge In Sql 2008

Merge In Sql 2008

Date post: 07-Nov-2014
Category:
Upload: catherine-eibner
View: 3,543 times
Download: 0 times
Share this document with a friend
Description:
 
9
A quick introduction to the new Merge Keyword in SQL 2008
Transcript
Page 1: Merge In Sql 2008

A quick introduction to the new Merge Keyword in SQL 2008

Page 2: Merge In Sql 2008

1. Basic logic behind the Merge Keyword2. Breakdown the Syntax3. Lets see it in action4. Q & A5. Next Steps

Page 3: Merge In Sql 2008

Senior Systems Designer for Cybner Computer Solutions who specialise in Microsoft Dynamics CRM Implementation & Integration

> 10 Years experience in the IT industry

Page 4: Merge In Sql 2008

Basic Upsert process Insert New Rows Update Existing Rows Delete removed Rows

Page 5: Merge In Sql 2008

[ WITH <common_table_expression> [,...n] ] MERGE [ TOP ( expression ) [ PERCENT ] ] [ INTO ] target_table [ [ AS ] table_alias ] [ WITH ( <merge_hint> ) ] USING <table_source> ON <search_condition> [ WHEN MATCHED [ AND <search_condition> ]         THEN

<merge_matched> ] [ WHEN [TARGET] NOT MATCHED [ AND <search_condition> ]

        THEN <merge_not_matched> ] [ WHEN SOURCE NOT MATCHED [ AND <search_condition> ]         THEN

<merge_ matched> ] <output_clause> [ OPTION ( <query_hint> [ ,...n ] ) ] ;

Page 6: Merge In Sql 2008

MERGE DESTINATIONUSING (This Source Data) ON this joinWhen Matched (exists in both tables)

Do Something – probably UpdateWhen Not Matched (A new record)

Do Something like InsertWhen Source Not Matched (Row has been

deleted from source table)Do Something like Delete from Destination

OUTPUT;

Page 7: Merge In Sql 2008

Solves some of the complex problems with populating a data warehouse

No knowledge of SSIS is needed Cleaner code Easy way to log the results of the Merge

statement Makes it easier to create data

warehouses which in turn can provide a basis for better business intelligence & analysis

Page 8: Merge In Sql 2008

Over to you…

Page 9: Merge In Sql 2008

Best Resources for SQL 2008 resources: Google!!! Search what you are trying to do http://www.sqlservercentral.com/ http://msdn.microsoft.com/en-us/library/

bb522522(SQL.100).aspx Download the latest CTP & Start Playing!!

More info on me: http://blog.cybner.com.au/ http://www.twitter.com/ceibner


Recommended