Merge statement Delete does not update indexed view in all cases
A merge statement that contains both an update clause and a delete clause, does not always update indexed views that refer the table.
Specifically, if the delete clause is the one that is triggered, and the update clause does not update any of the columns that are used by the indexed view, the deleted row is not removed from the indexed view.
The indexed view is therefore logically inconsistent; it contains rows that are no longer part of the source table. An SQL script that demonstrates the bug is included.
I have replicated the bug both on SQL Server 2014 SP2 Cumulative update 10, and on SQL server 2016 express SP1.
Vladimir Moldovanenko commented
Thanks Otto. The script fails on SQL 2017 CUM4 as well. Good find, I use indexed views quite a bit so good to know. Vladimir