with schemabinding
as
select id,customer_name,status,County
from dbo.Customers
where county = ‘Hertfordshire’
with check option go The WITH CHECK OPTION only works when you update, insert or delete using the view directly (this is a clue on how it’s been implemented). An example call would be: update vw_Customers_Hertfordshireset status = ‘M’
So, if we try and change the county from ‘Hertfordshire’ to ‘Cumbria’ for instance an error will result… update vw_Customers_Hertfordshireset county = ‘Cumbria’
go Msg 550, Level 16, State 1, Line 1The attempted insert or update failed because the target view either specifies WITH CHECK OPTION or spans a view that specifies WITH CHECK OPTION and one or more rows resulting from the operation did not qualify under the CHECK OPTION constraint.
The statement has been terminated.
Note that if we just update the base table directly then we get no error… update Customersset county = ‘Cumbria’
where county = ‘Hertfordshire’
go Works fine and updates the 3 rows.