SQL Server – How to Set Transaction Isolation Level in Table Value Multi Function

functionsisolation-levelsql serversql-server-2016

How do I set the transaction isolation level within in a table value multi function? I know it can be done in a stored procedure.

create function dbo.Test()
RETURNS @TestTable Table (test varchar(1000))
AS 
begin

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

I am receiving error below:

Msg 443, Level 16, State 15, Procedure abcde, Line 12
Invalid use of a side-effecting operator 'SET TRANSACTION ISOLATION LEVEL' within a function.

Best Answer

You can't set the transaction isolation level inside a function. You can use lock hints on the queries used in the functions instead.

Although you should really avoid using either READ UNCOMMITTED or the nolock lock hint.