Presentation Code
declare @i int = 10
select @i+10
go
select @i+20
go
/***********************************************************************/
exec sp_set_session_context @key=N'i', @value=N'10'
go
select SESSION_CONTEXT(N'i')+10
go
select SESSION_CONTEXT(N'i')+20
go
/***********************************************************************/
exec sp_set_session_context @key=N'i', @value=N'10'
go
select cast (SESSION_CONTEXT(N'i') as int )+10
go
select cast (SESSION_CONTEXT(N'i') as int )+20
go
/***********************************************************************/
exec sp_set_session_context @key=N'i', @value=N'10', @read_only=1
go
select cast (SESSION_CONTEXT(N'i') as int )+10
go
select cast (SESSION_CONTEXT(N'i') as int )+20
go
exec sp_set_session_context @key=N'i', @value=N'11', @read_only=1
go
/***********************************************************************/
-- The total size of the session context is limited to 256 kb.
SELECT * FROM sys.dm_os_memory_cache_counters WHERE type = 'CACHESTORE_SESSION_CONTEXT';
go