IT Questions and Answers :)

Tuesday, February 25, 2020

When called without an argument, which of the following returns the SQL Server login of the current security context.

When called without an argument, which of the following returns the SQL Server login of the current security context.

  • ORIGINAL_LOGIN()
  • SUSER_SNAME()
  • USER_NAME()
  • SUSER_SID()
When called without an argument, which of the following returns the SQL Server login of the current security context.

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/

SOURCE

https://docs.microsoft.com/en-us/sql/t-sql/functions/security-functions-transact-sql?view=sql-server-2017
Share:

0 comments:

Post a Comment

Popular Posts