Добро пожаловать в форум, Guest  >>   Войти | Регистрация | Поиск | Правила | В избранное | Подписаться
Все форумы / Microsoft SQL Server Новый топик    Ответить
 Полезная функция SESSION_CONTEXT, наконец-то сделали  [new]
Winnipuh
Member [заблокирован]

Откуда: Київ
Сообщений: 10428
In SQL Server 2016, there is a new built-in function called SESSION_CONTEXT(), matching Oracle's equivalent. It overcomes the above limitations in the following ways:

It supports key-value pairs - the keys are SYSNAME, while the values are SQL_VARIANT. SQL_VARIANT is admittedly not the easiest thing to work with, but it's a far cry better than bit-masking data into a single binary value.
It supports 256 kilobytes - an improvement of 2,000X over CONTEXT_INFO().
Any key can be marked as read only, so that a value cannot be changed once established.
It will work identically in SQL Server 2016 and Azure SQL Database - if you ask for a key that has not been set, you will always receive NULL.
You set key-value pairs using the stored procedure sys.sp_set_session_context - this takes three arguments:

@key SYSNAME (required)
@value SQL_VARIANT (required, nullable)
@read_only BIT (optional, default 0)
You might be curious how the stored procedure actually works by digging into the source code, but there is no way to do this, even under the DAC connection. It is actually an extended procedure under the covers, even though it doesn't have the xp_ prefix
...

https://www.mssqltips.com/sqlservertip/4094/phase-out-contextinfo-in-sql-server-2016-with-sessioncontext/
25 ноя 15, 14:03    [18470795]     Ответить | Цитировать Сообщить модератору
Все форумы / Microsoft SQL Server Ответить