A T-SQL trigger reads inserted or deleted into a variable, as if one row changed

tx0/sql:trigger-single-rowrecommendedwarningreliability/logicdepth fastbug

What it finds

A SQL Server trigger fires once per statement, with all changed rows in inserted and deleted. SELECT @id = id FROM inserted keeps the value of one arbitrary row, so a statement that changes several rows is handled as if it changed one.

From the rule's source, trigger_single_row.rs.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/sql:trigger-single-row" = "warning"

To keep one finding, suppress it with a reason: tx0 suppress ID --reason "..." writes the comment for it.

tx0 explain tx0/sql:trigger-single-row shows the same in the terminal. Found a false positive? Report it.