add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
DECLARE @Target table
(
c1 integer PRIMARY KEY,
c2 integer NOT NULL,
c3 integer NOT NULL
);

DECLARE @Source table
(
c1 integer NULL,
c2 integer NULL,
c3 integer NULL,
INDEX c CLUSTERED (c1)
);

INSERT @Target
(c1, c2, c3)
VALUES
(1, 0, 0);

INSERT @Source
(c1, c2, c3)
VALUES
(1, 2, NULL),
(1, NULL, 3);
set statistics xml on;

UPDATE T
SET T.c2 = S.c2,
T.c3 = S.c3
FROM @Target AS T
JOIN @Source AS S
ON S.c1 = T.c1
--OPTION (HASH GROUP)
Microsoft SQL Server 2005 XML Showplan
<ShowPlanXML xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan" Version="1.481" Build="14.0.3451.2"><BatchSequence><Batch><Statements><StmtSimple StatementText="UPDATE T&#xa;SET T.c2 = S.c2,&#xa; T.c3 = S.c3&#xa;FROM @Target AS T&#xa;JOIN @Source AS S&#xa; ON S.c1 = T.c1" StatementId="1" StatementCompId="6" StatementType="UPDATE" RetrievedFromCache="true" StatementSubTreeCost="0.0165724" StatementEstRows="1" SecurityPolicyApplied="false" StatementOptmLevel="FULL" QueryHash="0xB43E740E769130B6" QueryPlanHash="0xD7858543293275C5" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" CardinalityEstimationModelVersion="140"><StatementSetOptions QUOTED_IDENTIFIER="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" NUMERIC_ROUNDABORT="false"></StatementSetOptions><QueryPlan DegreeOfParallelism="0" NonParallelPlanReason="CouldNotGenerateValidParallelPlan" CachedPlanSize="32" CompileTime="15" CompileCPU="15" CompileMemory="296"><MemoryGrantInfo SerialRequiredMemory="0" SerialDesiredMemory="0"></MemoryGrantInfo><OptimizerHardwareDependentProperties EstimatedAvailableMemoryGrant="1258238" EstimatedPagesCached="78639" EstimatedAvailableDegreeOfParallelism="1" MaxCompileMemory="3643384"></OptimizerHardwareDependentProperties><TraceFlags IsCompileTime="1"><TraceFlag Value="460" Scope="Global"></TraceFlag><TraceFlag Value="8017" Scope="Global"></TraceFlag></TraceFlags><TraceFlags IsCompileTime="0"><TraceFlag Value="460" Scope="Global"></TraceFlag><TraceFlag Value="8017" Scope="Global"></TraceFlag></TraceFlags><QueryTimeStats ElapsedTime="0" CpuTime="0"></QueryTimeStats><RelOp NodeId="0" PhysicalOp="Clustered Index Update" LogicalOp="Update" EstimateRows="1" EstimateIO="0.01" EstimateCPU="1e-006" AvgRowSize="9" EstimatedTotalSubtreeCost="0.0165724" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="1" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="0" ActualLogicalReads="2" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualRowsRead="1" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><Update DMLRequestSort="0"><Object Table="[@Target]" Index="[PK__#B4C8175__3213663B89F164C7]" Alias="[T]" Storage="RowStore"></Object><SetPredicate><ScalarOperator ScalarString="@Target.[c2] as [T].[c2] = RaiseIfNullUpdate(@Source.[c2] as [S].[c2]),@Target.[c3] as [T].[c3] = RaiseIfNullUpdate(@Source.[c3] as [S].[c3])"><ScalarExpressionList><ScalarOperator><MultipleAssign><Assign><ColumnReference Table="@Target" Alias="[T]" Column="c2"></ColumnReference><ScalarOperator><Intrinsic FunctionName="RaiseIfNullUpdate"><ScalarOperator><Identifier><ColumnReference Table="@Source" Alias="[S]" Column="c2"></ColumnReference></Identifier></ScalarOperator></Intrinsic></ScalarOperator></Assign><Assign><ColumnReference Table="@Target" Alias="[T]" Column="c3"></ColumnReference><ScalarOperator><Intrinsic FunctionName="RaiseIfNullUpdate"><ScalarOperator><Identifier><ColumnReference Table="@Source" Alias="[S]" Column="c3"></ColumnReference></Identifier></ScalarOperator></Intrinsic></ScalarOperator></Assign></MultipleAssign></ScalarOperator></ScalarExpressionList></ScalarOperator></SetPredicate><RelOp NodeId="1" PhysicalOp="Stream Aggregate" LogicalOp="Aggregate" EstimateRows="1" EstimateIO="0" EstimateCPU="1e-006" AvgRowSize="19" EstimatedTotalSubtreeCost="0.00657138" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Table="@Target" Alias="[T]" Column="c1"></ColumnReference><ColumnReference Table="@Source" Alias="[S]" Column="c2"></ColumnReference><ColumnReference Table="@Source" Alias="[S]" Column="c3"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="1" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><StreamAggregate><DefinedValues><DefinedValue><ColumnReference Table="@Source" Alias="[S]" Column="c2"></ColumnReference><ScalarOperator ScalarString="ANY(@Source.[c2] as [S].[c2])"><Aggregate Distinct="0" AggType="ANY"><ScalarOperator><Identifier><ColumnReference Table="@Source" Alias="[S]" Column="c2"></ColumnReference></Identifier></ScalarOperator></Aggregate></ScalarOperator></DefinedValue><DefinedValue><ColumnReference Table="@Source" Alias="[S]" Column="c3"></ColumnReference><ScalarOperator ScalarString="ANY(@Source.[c3] as [S].[c3])"><Aggregate Distinct="0" AggType="ANY"><ScalarOperator><Identifier><ColumnReference Table="@Source" Alias="[S]" Column="c3"></ColumnReference></Identifier></ScalarOperator></Aggregate></ScalarOperator></DefinedValue></DefinedValues><GroupBy><ColumnReference Table="@Target" Alias="[T]" Column="c1"></ColumnReference></GroupBy><RelOp NodeId="2" PhysicalOp="Nested Loops" LogicalOp="Inner Join" EstimateRows="1" EstimateIO="0" EstimateCPU="4.18e-006" AvgRowSize="19" EstimatedTotalSubtreeCost="0.00657038" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Table="@Target" Alias="[T]" Column="c1"></ColumnReference><ColumnReference Table="@Source" Alias="[S]" Column="c2"></ColumnReference><ColumnReference Table="@Source" Alias="[S]" Column="c3"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="2" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><NestedLoops Optimized="0"><OuterReferences><ColumnReference Table="@Target" Alias="[T]" Column="c1"></ColumnReference></OuterReferences><RelOp NodeId="3" PhysicalOp="Clustered Index Scan" LogicalOp="Clustered Index Scan" EstimateRows="1" EstimatedRowsRead="1" EstimateIO="0.003125" EstimateCPU="0.0001581" AvgRowSize="11" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="0" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Table="@Target" Alias="[T]" Column="c1"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="1" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="1" ActualLogicalReads="2" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualRowsRead="1" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><IndexScan Ordered="1" ForcedIndex="0" ForceScan="0" NoExpandHint="0" Storage="RowStore"><DefinedValues><DefinedValue><ColumnReference Table="@Target" Alias="[T]" Column="c1"></ColumnReference></DefinedValue></DefinedValues><Object Table="[@Target]" Index="[PK__#B4C8175__3213663B89F164C7]" Alias="[T]" Storage="RowStore"></Object></IndexScan></RelOp><RelOp NodeId="4" PhysicalOp="Clustered Index Seek" LogicalOp="Clustered Index Seek" EstimateRows="1" EstimatedRowsRead="1" EstimateIO="0.003125" EstimateCPU="0.0001581" AvgRowSize="15" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="0" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Table="@Source" Alias="[S]" Column="c2"></ColumnReference><ColumnReference Table="@Source" Alias="[S]" Column="c3"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="2" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="1" ActualLogicalReads="2" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualRowsRead="2" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><IndexScan Ordered="1" ScanDirection="FORWARD" ForcedIndex="0" ForceSeek="0" ForceScan="0" NoExpandHint="0" Storage="RowStore"><DefinedValues><DefinedValue><ColumnReference Table="@Source" Alias="[S]" Column="c2"></ColumnReference></DefinedValue><DefinedValue><ColumnReference Table="@Source" Alias="[S]" Column="c3"></ColumnReference></DefinedValue></DefinedValues><Object Table="[@Source]" Index="[c]" Alias="[S]" Storage="RowStore"></Object><SeekPredicates><SeekPredicateNew><SeekKeys><Prefix ScanType="EQ"><RangeColumns><ColumnReference Table="@Source" Alias="[S]" Column="c1"></ColumnReference></RangeColumns><RangeExpressions><ScalarOperator ScalarString="@Target.[c1] as [T].[c1]"><Identifier><ColumnReference Table="@Target" Alias="[T]" Column="c1"></ColumnReference></Identifier></ScalarOperator></RangeExpressions></Prefix></SeekKeys></SeekPredicateNew></SeekPredicates></IndexScan></RelOp></NestedLoops></RelOp></StreamAggregate></RelOp></Update></RelOp></QueryPlan></StmtSimple></Statements></Batch></BatchSequence></ShowPlanXML>
UPDATE T SET T.c2 = S.c2, T.c3 = S.c3 FROM @Target AS T JOIN @Source AS S ON S.c1 = T.c1
UPDATE
UPDATE
Cached plan size32 KB
Estimated Operator Cost0 (0%)
Estimated Subtree Cost0.0165724
Degree of Parallelism0
Estimated Number of Rows1
Statement
UPDATE T SET T.c2 = S.c2, T.c3 = S.c3 FROM @Target AS T JOIN @Source AS S ON S.c1 = T.c1
Clustered Index Update
(Update)
Cost: 60%
Clustered Index Update
Physical OperationClustered Index Update
Logical OperationUpdate
Actual Execution ModeRow
Estimated Execution ModeRow
Number of Rows Read1
Actual Number of Rows1
Actual Number of Batches0
Estimated Operator Cost0.010001 (60%)
Estimated I/O Cost0.01
Estimated CPU Cost0.000001
Estimated Subtree Cost0.0165724
Estimated Number of Executions1
Number of Executions1
Estimated Number of Rows1
Estimated Row Size9 B
Actual Rebinds0
Actual Rewinds0
Node ID0
Object
[@Target].[PK__#B4C8175__3213663B89F164C7].[T]
Predicate
@Target.[c2] as [T].[c2] = RaiseIfNullUpdate(@Source.[c2] as [S].[c2]),@Target.[c3] as [T].[c3] = RaiseIfNullUpdate(@Source.[c3] as [S].[c3])
Stream Aggregate
(Aggregate)
Cost: 0%
Stream Aggregate
Compute summary values for groups of rows in a suitably sorted stream.
Physical OperationStream Aggregate
Logical OperationAggregate
Actual Execution ModeRow
Estimated Execution ModeRow
Actual Number of Rows1
Actual Number of Batches0
Estimated Operator Cost0.000001 (0%)
Estimated I/O Cost0
Estimated CPU Cost0.000001
Estimated Subtree Cost0.0065714
Estimated Number of Executions1
Number of Executions1
Estimated Number of Rows1
Estimated Row Size19 B
Actual Rebinds0
Actual Rewinds0
Node ID1
Output List
@Target.[T].c1
@Source.[S].c2
@Source.[S].c3
Nested Loops
(Inner Join)
Cost: 0%
Nested Loops
For each row in the top (outer) input, scan the bottom (inner) input, and output matching rows.
Physical OperationNested Loops
Logical OperationInner Join
Actual Execution ModeRow
Estimated Execution ModeRow
Actual Number of Rows2
Actual Number of Batches0
Estimated Operator Cost0.0000042 (0%)
Estimated I/O Cost0
Estimated CPU Cost0.0000042
Estimated Subtree Cost0.0065704
Estimated Number of Executions1
Number of Executions1
Estimated Number of Rows1
Estimated Row Size19 B
Actual Rebinds0
Actual Rewinds0
Node ID2
Output List
@Target.[T].c1
@Source.[S].c2
@Source.[S].c3
Outer References
@Target.[T].c1
Clustered Index Scan
[@Target].[PK__#B4C8175__3213663B89…
Cost: 20%
Clustered Index Scan
Scanning a clustered index, entirely or only a range.
Physical OperationClustered Index Scan
Logical OperationClustered Index Scan
Actual Execution ModeRow
Estimated Execution ModeRow
StorageRowStore
Number of Rows Read1
Actual Number of Rows1
Actual Number of Batches0
Estimated Operator Cost0.0032831 (20%)
Estimated I/O Cost0.003125
Estimated CPU Cost0.0001581
Estimated Subtree Cost0.0032831
Estimated Number of Executions1
Number of Executions1
Estimated Number of Rows to be Read1
Estimated Number of Rows1
Estimated Row Size11 B
Actual Rebinds0
Actual Rewinds0
OrderedTrue
Node ID3
Output List
@Target.[T].c1
Object
[@Target].[PK__#B4C8175__3213663B89F164C7].[T]
Clustered Index Seek
[@Source].[c].[S]
Cost: 20%
Clustered Index Seek
Scanning a particular range of rows from a clustered index.
Physical OperationClustered Index Seek
Logical OperationClustered Index Seek
Actual Execution ModeRow
Estimated Execution ModeRow
StorageRowStore
Number of Rows Read2
Actual Number of Rows2
Actual Number of Batches0
Estimated Operator Cost0.0032831 (20%)
Estimated I/O Cost0.003125
Estimated CPU Cost0.0001581
Estimated Subtree Cost0.0032831
Estimated Number of Executions1
Number of Executions1
Estimated Number of Rows to be Read1
Estimated Number of Rows1
Estimated Row Size15 B
Actual Rebinds0
Actual Rewinds0
OrderedTrue
Node ID4
Output List
@Source.[S].c2
@Source.[S].c3
Object
[@Source].[c].[S]
Seek Predicates
Seek Keys[1]: Prefix: @Source.c1 = Scalar Operator(@Target.[c1] as [T].[c1])
c1 c2 c3
1 2 3