Often, T-SQL developers will ask if there is a way to access some kind of a call stack at runtime. Either the full call stack or simply the previous calling procedure. Some uses for this would be to debug a procedure, or to restrict users from updating a table unless it was done through a particular stored procedure.
As of SQL Server 2008, no feature exists. While searching the web for such a feature, I came across a feature request from 2006 by Erland Sommarskog. The feature has not yet been added, so we’ll just have to make do with workarounds. In this tip, I will show you how to make your own callstack using CONTEXT_INFO().
More...