SESSION_USER (Transact-SQL)

Use SESSION_USER with DEFAULT constraints in either the CREATE TABLE or ALTER TABLE statements, or use it as any standard function. SESSION_USER can be inserted into a table when no default value is specified. This function takes no arguments. SESSION_USER can be used in queries.

If SESSION_USER is called after a context switch, SESSION_USER will return the user name of the impersonated context.

Records added to the table will be stamped with the user name of the current user. In this example, Wanida, Sylvester, and Alejandro verify receipt of shipments. This can be emulated by switching user context by using EXECUTE AS.