Tuesday, 4 November 2025

Context info statement in SQL Server

The set context_info statement in SQL Server allows us to store up to 128 bytes of binary data in the current session or connection.

This is useful for tracing session specific info like

Ø  User ID

Ø  Application Context

Ø  Temporary permission

Ø  Audit or Login meta data

See the example

declare @userID varchar(20);

set @userID='Bagesh';

declare @a varbinary(max), @b varbinary(max)

set @a= cast(@userID as varbinary); 

set context_info @a 

SELECT CONTEXT_INFO(); 

set @b =CONTEXT_INFO();

select cast(@b as varchar)

 

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts