2

After doing some research, I can't really find a way to use a Snapshot Isolation level in a SQL Server view.

Is there some way to achieve it, or if it is indeed impossible, what is the best way to approach a situation, when I'd like my views to not block writers, but still avoid using NOLOCK hint on them?

asked Jul 6, 2015 at 15:59

2 Answers 2

1

I think you can't force the view to always use Snapshot isolation (Snapshot isolation doesn't have query hints because it's on the transaction level, not the query level). The callers of the view would have to set the isolation themselves:

SET TRANSACTION ISOLATION LEVEL SNAPSHOT
SELECT * FROM dbo.YourView
answered Dec 19, 2017 at 14:24

Comments

0

To activate Snapshot isolation level on a database, use this code:

ALTER DATABASE [your DB] SET READ_COMMITTED_SNAPSHOT ON;
ALTER DATABASE [your DB] SET ALLOW_SNAPSHOT_ISOLATION ON;

Your views and tables will use it automaticaly when ON.

More info [https://technet.microsoft.com/en-us/library/ms175095(v=sql.105).aspx][1]

answered Jul 6, 2015 at 17:44

1 Comment

Thanks for your answer! I should've been more articulate: I'm not talking about Read Committed Snapshot, but only about Snapshot Isolation, which should be explicitly set on a statement/procedure level. I understand setting Read Committed will affect all queires to a database

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.