When called without an argument, which of the following returns the SQL Server login of the current security context.
- SUSER_SNAME()
- SUSER_SID()
- ORIGINAL_LOGIN()
- USER_NAME()
EXPLANATION
SUSER_SNAME() - returns the login of the current security context.
ORIGINAL_LOGIN() - returns login of original connection context. It is not affected by context-switching.
USER_NAME() - returns the database user name of the current security context.
SUSER_SID() - Returns the Security Identifier (SID) of the current security context.
SQL
Server has system-level logins and database users. While they often
have the same username, they are distinct from one another. Logins are
needed to gain access and set system-level permissions to SQL Server,
while Users are needed for access and permissions to specific databases.
The current security context in SQL Server
can be changed, known as context-switching or impersonation, with the
use of the EXECUTE AS and REVERT statements in a script or batch.
Additional reading:
SQL
Server Security Principals -
https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/principals-database-engine?view=sql-server-2017
Context-switching - https://sqlity.net/en/1783/changing-security-context-execute-revert/
0 comments:
Post a Comment