Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a SqlServer View always up to date?

Will a sqlserver view always be up to date or can there be a delay on it?

like image 791
Lieven Cardoen Avatar asked Dec 03 '22 06:12

Lieven Cardoen


1 Answers

That depends on the transaction isolation level the view runs at. By default, views run at READ COMMITTED. The view will return only committed data. As long as your view consists of only one SQL statement, and doesn't call user defined functions or extended procedures, it will be consistent.

But views can also run at a more risky isolation level. For example, this view specifies nolock so it runs at READ UNCOMMITTED:

create view dbo.MyView
as select * from dbo.MyTable with (nolock)

This view can return values that are part of a transaction that will be rolled back (dirty read.) This transaction isolation level trades consistency for performance.

like image 131
Andomar Avatar answered Jan 05 '23 15:01

Andomar