SYSTEM_USER is a built-in, zero-argument scalar function that reports the identity under which the current connection is authenticated. In SQL Server it returns the login name for SQL logins or the Windows domain\username for Windows-authenticated logins. Because it reflects the security context of the connection, the value is constant for the lifetime of the session and is unaffected by database context changes or SET USER_NAME statements.The function is evaluated on the server, making it immune to client-side spoofing. It is non-deterministic from a query-optimizer standpoint (its value can differ between sessions) yet deterministic within a single session.Unlike CURRENT_USER or SESSION_USER, which can be influenced by EXECUTE AS or SETUSER, SYSTEM_USER always reports the original login context. In MySQL, SYSTEM_USER() is a synonym for CURRENT_USER(), returning user@host. PostgreSQL and SQLite do not implement SYSTEM_USER, but provide CURRENT_USER and SESSION_USER as alternatives.Typical uses include auditing (stamping rows with the login that performed an operation), conditional logic in stored procedures, and troubleshooting permission issues. Because the returned string length and format depend on the authentication method, designers should use NVARCHAR(128) or similar columns to store it.Caveats:- Returns one string only; does not separate domain and account into different columns.- Cannot be used in CHECK constraints in Azure SQL Database.- For contained databases in SQL Server, returns the contained database user name when using contained database authentication.
CURRENT_USER, SESSION_USER, USER_NAME(), SUSER_SNAME(), ORIGINAL_LOGIN()
SQL Server 2000
SYSTEM_USER outputs the login or operating-system account that established the current database connection.
No. It always reports the original login, ignoring impersonation done with EXECUTE AS or SETUSER.
Yes. Define the column with `DEFAULT (SYSTEM_USER)` to automatically capture the login name on INSERT.
Yes, MySQL implements SYSTEM_USER() as a synonym for CURRENT_USER(), returning 'user@host' for the connection.