SlideShare a Scribd company logo
1 of 22
Presented by Steve Stedman
and Aaron Buma
Welcome
 Welcome to all those joining us remotely.
 For any questions via Google On Air Broadcasts, we will
address most of these at the end of the training.
 Training provided by Emergency Reporting
 http://EmergencyReporting.com
 Slides and sample code are available at:
 http://SteveStedman.com
Welcome Viewers From
 Bellingham, WA
 Riverview, FL
 Warren, MI
 Jacksonville, FL
 Chennai, India
 Belarus
 Trowbridge, UK
 Hyderabad, India
 Bucharest, Romania
Live Broadcast
 Using Google On Air Broadcasts
 There is about a 40 to 50 second delay from live to what
you see.
 We are still learning how to properly use Google On Air
Broadcasts. Please be patient.
 Session will be available on my YouTube Channel about
an hour after the presentation ends.
 http://SteveStedman.com/YouTube
Questions
 We will have time for questions at the end of the session.
 Q&A available via Google On Air Hangout panel. Click the
3x3 grid icon near the top right, then select Q&A to see
what people are asking, or to ask your own question.
 When you ask a question, it shows up for us about 40 to 50
seconds delayed.
A Question From a Viewer
“on your webpage you mention the training will be covered
in 45 weeks, do you mean to say that the preparation for
the 70-461 exam will take almost a year.”
That was the original plan, however we have had several
weeks that we have doubled up content from the original
plan, so I am thinking it will be around 30 weeks,
instead of the original estimated 45.
Agenda
 Merge Statement
 Data Recursion
 Self JOIN
 Recursive CTE
Presented by Aaron Buma
Without Merge – Update/Insert
 Without merge, conditional Inserts/Updates/Deletes
require multiple statements
 Example: Combine your baseball card book with a new
deck
 Without Merge:
 “Insert” into your deck cards you don’t have
 “Update” the quantity of cards you have if you already have it
and if the value is > $5
Merge - Example
 With Merge:
Merge Statement
 What it can do in one statement:
 Perform 2 or 3 UPDATE, INSERT, DELETE statements
 2 Statements
 One for a MATCHED
 One for NOT MATCHED
 3 Statements
 One for MATCHED x = y AND x > z
 One for MATCHED x = y
 One for NOT MATCHED
Merge Statement - Advanced
 The source ‘table’ can be a derived table
 Variables
 Subselect
 You can use the OUTPUT clause to log data changes
Merge statement
 Requires a semi-colon
 Can have up to 3 MATCHED (2 WHEN, 1 NOT
“UPSERT” is misnomer, you can UPDATE, INSERT or
DELETE in a MERGE statement
 Introduced in 2008
MERGE Statements
Demo
Presented by Steve Stedman
Recursion
 SELF-JOIN – some consider recursive
 Common Table Expressions
 Considered recursive when the CTE references itself
 Recursion stops
 When the recursive query produces no results
 Or specify MAXRECURSION
Uses for Recursion
 Hierarchical Data
 Tree Path
 Recursive Calculations (mathematic sequences)
 String Parsing
 Finding Holes
 Replacing a Numbers Table
 Date Calculations
Recursion
Demo
Recursion Usage Summary
 Hierarchical Data
 Tree Path
 Recursive Calculations (mathematic sequences)
 String Parsing
 Finding Holes
 Replacing a Numbers Table
 Date Calculations
Any Questions?
 Merge Statement
 Data Recursion
 Self JOIN
 Recursive CTE
For More Information
 Visit http://EmergencyReporting.com to find out more
about Emergency Reporting.
 Aaron on the web
 http://AaronBuma.com
 Twitter: @AaronDBuma
 Steve on the web
 http://SteveStedman.com
 twitter: @SqlEmt
Tune in next week
 Thursday March 5th at
9:00am (pacific time).
 Topics - Review /
Lightning Talks
 Null
 Expressions
 Identity
 Aggregation
 Top, Ranking and
Aggregation
 OUTPUT Clause
 Derived Tables
 Merge Statement
 Set Operators
 Derived Tables
 Common Table
Expressions
 Recursive Queries
 5 minutes per topic,
followed by Q&A

More Related Content

Similar to SQL Server MERGE statement and recursive queries for the 70-461 Certificatoin

Final Exam Due Friday, Week EightInstructions  Each response is.docx
Final Exam Due Friday, Week EightInstructions  Each response is.docxFinal Exam Due Friday, Week EightInstructions  Each response is.docx
Final Exam Due Friday, Week EightInstructions  Each response is.docx
mydrynan
 
1NOTE This is a template to help you format Project Part .docx
1NOTE This is a template to help you format Project Part .docx1NOTE This is a template to help you format Project Part .docx
1NOTE This is a template to help you format Project Part .docx
robert345678
 
2011 presentation powerpoint
2011 presentation powerpoint2011 presentation powerpoint
2011 presentation powerpoint
davewoods
 
Underfitting and Overfitting in Machine Learning
Underfitting and Overfitting in Machine LearningUnderfitting and Overfitting in Machine Learning
Underfitting and Overfitting in Machine Learning
Abdullah al Mamun
 
Running head NATURE VERSUS NURTURE .docx
Running head NATURE VERSUS NURTURE                             .docxRunning head NATURE VERSUS NURTURE                             .docx
Running head NATURE VERSUS NURTURE .docx
charisellington63520
 

Similar to SQL Server MERGE statement and recursive queries for the 70-461 Certificatoin (20)

Bus 308 Effective Communication - snaptutorial.com
Bus 308  Effective Communication - snaptutorial.comBus 308  Effective Communication - snaptutorial.com
Bus 308 Effective Communication - snaptutorial.com
 
ACT Readiness
ACT ReadinessACT Readiness
ACT Readiness
 
Data Science: The Product Manager's Primer
Data Science: The Product Manager's PrimerData Science: The Product Manager's Primer
Data Science: The Product Manager's Primer
 
Final Exam Due Friday, Week EightInstructions  Each response is.docx
Final Exam Due Friday, Week EightInstructions  Each response is.docxFinal Exam Due Friday, Week EightInstructions  Each response is.docx
Final Exam Due Friday, Week EightInstructions  Each response is.docx
 
Psych 625Education Specialist / snaptutorial.com
Psych 625Education Specialist / snaptutorial.comPsych 625Education Specialist / snaptutorial.com
Psych 625Education Specialist / snaptutorial.com
 
1NOTE This is a template to help you format Project Part .docx
1NOTE This is a template to help you format Project Part .docx1NOTE This is a template to help you format Project Part .docx
1NOTE This is a template to help you format Project Part .docx
 
evaluation and credibility-Part 2
evaluation and credibility-Part 2evaluation and credibility-Part 2
evaluation and credibility-Part 2
 
PSYCH 625 Extraordinary Life/newtonhelp.com 
PSYCH 625 Extraordinary Life/newtonhelp.com PSYCH 625 Extraordinary Life/newtonhelp.com 
PSYCH 625 Extraordinary Life/newtonhelp.com 
 
PSYCH 625  Focus Dreams/newtonhelp.com
PSYCH 625  Focus Dreams/newtonhelp.comPSYCH 625  Focus Dreams/newtonhelp.com
PSYCH 625  Focus Dreams/newtonhelp.com
 
2011 presentation powerpoint
2011 presentation powerpoint2011 presentation powerpoint
2011 presentation powerpoint
 
Tutorial Google Forms
Tutorial Google FormsTutorial Google Forms
Tutorial Google Forms
 
Batting Averages and Slugging %s
Batting Averages and Slugging %sBatting Averages and Slugging %s
Batting Averages and Slugging %s
 
Psych 625 Effective Communication - tutorialrank.com
Psych 625  Effective Communication - tutorialrank.comPsych 625  Effective Communication - tutorialrank.com
Psych 625 Effective Communication - tutorialrank.com
 
Kevin Gumienny ELS 2015 Presentation: The Brainy Way to Better Training
Kevin Gumienny ELS 2015 Presentation:  The Brainy Way to Better TrainingKevin Gumienny ELS 2015 Presentation:  The Brainy Way to Better Training
Kevin Gumienny ELS 2015 Presentation: The Brainy Way to Better Training
 
Underfitting and Overfitting in Machine Learning
Underfitting and Overfitting in Machine LearningUnderfitting and Overfitting in Machine Learning
Underfitting and Overfitting in Machine Learning
 
PSYCH 625 Exceptional Education - snaptutorial.com
PSYCH 625   Exceptional Education - snaptutorial.comPSYCH 625   Exceptional Education - snaptutorial.com
PSYCH 625 Exceptional Education - snaptutorial.com
 
PSYCH 625 Effective Communication - snaptutorial.com
PSYCH 625 Effective Communication - snaptutorial.comPSYCH 625 Effective Communication - snaptutorial.com
PSYCH 625 Effective Communication - snaptutorial.com
 
70 270 q & a
70 270 q & a70 270 q & a
70 270 q & a
 
Machine learning and_nlp
Machine learning and_nlpMachine learning and_nlp
Machine learning and_nlp
 
Running head NATURE VERSUS NURTURE .docx
Running head NATURE VERSUS NURTURE                             .docxRunning head NATURE VERSUS NURTURE                             .docx
Running head NATURE VERSUS NURTURE .docx
 

Recently uploaded

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
Muhammad Subhan
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Recently uploaded (20)

UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 

SQL Server MERGE statement and recursive queries for the 70-461 Certificatoin

  • 1. Presented by Steve Stedman and Aaron Buma
  • 2. Welcome  Welcome to all those joining us remotely.  For any questions via Google On Air Broadcasts, we will address most of these at the end of the training.  Training provided by Emergency Reporting  http://EmergencyReporting.com  Slides and sample code are available at:  http://SteveStedman.com
  • 3. Welcome Viewers From  Bellingham, WA  Riverview, FL  Warren, MI  Jacksonville, FL  Chennai, India  Belarus  Trowbridge, UK  Hyderabad, India  Bucharest, Romania
  • 4. Live Broadcast  Using Google On Air Broadcasts  There is about a 40 to 50 second delay from live to what you see.  We are still learning how to properly use Google On Air Broadcasts. Please be patient.  Session will be available on my YouTube Channel about an hour after the presentation ends.  http://SteveStedman.com/YouTube
  • 5. Questions  We will have time for questions at the end of the session.  Q&A available via Google On Air Hangout panel. Click the 3x3 grid icon near the top right, then select Q&A to see what people are asking, or to ask your own question.  When you ask a question, it shows up for us about 40 to 50 seconds delayed.
  • 6. A Question From a Viewer “on your webpage you mention the training will be covered in 45 weeks, do you mean to say that the preparation for the 70-461 exam will take almost a year.” That was the original plan, however we have had several weeks that we have doubled up content from the original plan, so I am thinking it will be around 30 weeks, instead of the original estimated 45.
  • 7. Agenda  Merge Statement  Data Recursion  Self JOIN  Recursive CTE
  • 9. Without Merge – Update/Insert  Without merge, conditional Inserts/Updates/Deletes require multiple statements  Example: Combine your baseball card book with a new deck  Without Merge:  “Insert” into your deck cards you don’t have  “Update” the quantity of cards you have if you already have it and if the value is > $5
  • 10. Merge - Example  With Merge:
  • 11. Merge Statement  What it can do in one statement:  Perform 2 or 3 UPDATE, INSERT, DELETE statements  2 Statements  One for a MATCHED  One for NOT MATCHED  3 Statements  One for MATCHED x = y AND x > z  One for MATCHED x = y  One for NOT MATCHED
  • 12. Merge Statement - Advanced  The source ‘table’ can be a derived table  Variables  Subselect  You can use the OUTPUT clause to log data changes
  • 13. Merge statement  Requires a semi-colon  Can have up to 3 MATCHED (2 WHEN, 1 NOT “UPSERT” is misnomer, you can UPDATE, INSERT or DELETE in a MERGE statement  Introduced in 2008
  • 16. Recursion  SELF-JOIN – some consider recursive  Common Table Expressions  Considered recursive when the CTE references itself  Recursion stops  When the recursive query produces no results  Or specify MAXRECURSION
  • 17. Uses for Recursion  Hierarchical Data  Tree Path  Recursive Calculations (mathematic sequences)  String Parsing  Finding Holes  Replacing a Numbers Table  Date Calculations
  • 19. Recursion Usage Summary  Hierarchical Data  Tree Path  Recursive Calculations (mathematic sequences)  String Parsing  Finding Holes  Replacing a Numbers Table  Date Calculations
  • 20. Any Questions?  Merge Statement  Data Recursion  Self JOIN  Recursive CTE
  • 21. For More Information  Visit http://EmergencyReporting.com to find out more about Emergency Reporting.  Aaron on the web  http://AaronBuma.com  Twitter: @AaronDBuma  Steve on the web  http://SteveStedman.com  twitter: @SqlEmt
  • 22. Tune in next week  Thursday March 5th at 9:00am (pacific time).  Topics - Review / Lightning Talks  Null  Expressions  Identity  Aggregation  Top, Ranking and Aggregation  OUTPUT Clause  Derived Tables  Merge Statement  Set Operators  Derived Tables  Common Table Expressions  Recursive Queries  5 minutes per topic, followed by Q&A