You are on page 1of 9

Parent Data, Child Data,

and Keeping them in sync


Cascading data changes, recursive queries, and other queries
Who is Richard Mathis

CTO of CHSI Technologies


Designed and Implemented databases
since 1999.
Professed all things but especially data
geek
Min-maxer, constantly looking for the
best new thing to eke out 1-2% more
performance.
Course Objectives

Improve performance by reusing expensive queries


Create hierarchal resultsets
Store or build temporary data
Using MERGE instead of UPDATE
Synchronize data with MERGE
Cascading INSERT/UPDATE Statements
Queries inside
Queries
Separate queries for
readability
Use the output of an
expensive query multiple
times for performance
Queries Joined on
Themselves
Create queries that create a dynamic
amount of children rows
Hierarchal parent-child-child-etc
relationships
Temporary
Storage
For our purpose, were
going to avoid #Tables.
If in doubt, try to use in the
order CTE, Table Variable,
#Table
These constructs can both
help and hurt database
and query performance.
MERGE

Looks complicated, but


very explicit
Somewhat handles race
conditions, but still needs
HOLDLOCK
MERGE from Parent
to Child to Child

Often changes at a top level should


extend to all of their related tables.
In many scenarios, can be reran
without creating duplicates.
Questions

Samples, problems, syntax?

Any future Questions can be sent to


support@chsitech.com

You might also like