Refer to this SQL Fiddle and click the "Execution Plan" link at the bottom left for context.
As you can see, the CountryGroup
table has a single row with CountryId = 1
. I then update the CountryGroup
table with a statement that should effectively be a no-op (setting CountryId = 1
when it's already 1). This triggers the rebuild of the clustered index UX_CountryGroupView_Id
on the view, which is a relatively expensive operation (60% of the query cost). In the database I'm actually working with, the actual cost is a lot higher, hence this question.
Does SQL Server only check @@rowcount
when determining if it should update indexes, or does/can it look at the data to see if it's changed and whether it should expend the effort of rebuilding? It seems that the former is the case, but is it possible to specify the latter behaviour, or control what SQL Server does in this circumstance?
Please note, I have no control over the SQL update
statement, which is being autogenerated.