go backarticles

Articles of SQLschool.gr Team

Session Context in SQL Server

Antonios Chatzipavlis





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

Relative Articles

Leave your comment

Login with your SQLschool.gr account if you want to comment on this article.


PASS chapter logo

The Official PASS Local Group for Greece

1428 33 592 27 39 1307
sql school greece logo
© 2010-2019 All rights reserved