Date post: | 07-Nov-2014 |
Category: |
Business |
Upload: | catherine-eibner |
View: | 3,543 times |
Download: | 0 times |
A quick introduction to the new Merge Keyword in SQL 2008
1. Basic logic behind the Merge Keyword2. Breakdown the Syntax3. Lets see it in action4. Q & A5. Next Steps
Senior Systems Designer for Cybner Computer Solutions who specialise in Microsoft Dynamics CRM Implementation & Integration
> 10 Years experience in the IT industry
Basic Upsert process Insert New Rows Update Existing Rows Delete removed Rows
[ 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 ] ) ] ;
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;
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
Over to you…
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