1,suser_sname
Returns the login name associated with a security identification number (SID).
Syntax
SUSER_SNAME ( [ server_user_sid ] )
Arguments
- server_user_sid
-
Is the optional login security identification number. server_user_sid is varbinary(85). server_user_sid can be the security identification number of any SQL Server login or Microsoft Windows user or group. If server_user_sid is not specified, information about the current user is returned. If the parameter contains the word NULL will return NULL.
SUSER_SNAME can be used as a DEFAULT constraint in either ALTER TABLE or CREATE TABLE. SUSER_SNAME can be used in a select list, in a WHERE clause, and anywhere an expression is allowed. SUSER_SNAME must always be followed by parentheses, even if no parameter is specified.
When called without an argument, SUSER_SNAME returns the name of the current security context. When called without an argument within a batch that has switched context by using EXECUTE AS, SUSER_SNAME returns the name of the impersonated context. When called from an impersonated context, ORIGINAL_LOGIN returns the name of the original context.
2,suser_name
Returns the login identification name of the user.
Syntax
SUSER_NAME ( [ server_user_id ] )
Arguments
- server_user_id
-
Is the login identification number of the user. server_user_id, which is optional, is int. server_user_id can be the login identification number of any SQL Server login or Microsoft Windows user or group that has permission to connect to an instance of SQL Server. If server_user_id is not specified, the login identification name for the current user is returned. If the parameter contains the word NULL will return NULL.
In SQL Server version 7.0, the security identification number (SID) replaced the server user identification number (SUID).
SUSER_NAME returns a login name only for a login that has an entry in the syslogins system table.
SUSER_NAME can be used in a select list, in a WHERE clause, and anywhere an expression is allowed, and must always be followed by parentheses, even if no parameter is specified.
3,USER_NAME
Returns a database user name from a specified identification number.
Syntax
USER_NAME ( [ id ] )
Arguments
- id
-
Is the identification number associated with a database user. id is int. The parentheses are required.
Remarks
When id is omitted, the current user in the current context is assumed. If the parameter contains the word NULL will return NULL.When USER_NAME is called without specifying an id after an EXECUTE AS statement, USER_NAME returns the name of the impersonated user. If a Windows principal accesses the database by way of membership in a group, USER_NAME returns the name of the Windows principal instead of the group.
4,USER
Allows a system-supplied value for the database user name of the current user to be inserted into a table when no default value is specified.
Syntax
USER
Remarks
USER provides the same functionality as the USER_NAME system function.
Use USER with DEFAULT constraints in either the CREATE TABLE or ALTER TABLE statements, or use as any standard function.
USER always returns the name of the current context. When called after an EXECUTE AS statement, USER returns the name of the impersonated context.
If a Windows principal accesses the database by way of membership in a group, USER returns the name of the Windows principal instead of the name of the group.
5,SYSTEM_USER
Allows a system-supplied value for the current login to be inserted into a table when no default value is specified.
Syntax
SYSTEM_USER
Remarks
You can use the SYSTEM_USER function with DEFAULT constraints in the CREATE TABLE and ALTER TABLE statements. You can also use it as any standard function.
If the user name and login name are different, SYSTEM_USER returns the login name.
If the current user is logged in to SQL Server by using Windows Authentication, SYSTEM_USER returns the Windows login identification name in the form: DOMAIN\user_login_name. However, if the current user is logged in to SQL Server by using SQL Server Authentication, SYSTEM_USER returns the SQL Server login identification name, such as WillisJo for a user logged in as WillisJo.
SYSTEM_USER returns the name of the currently executing context. If the EXECUTE AS statement has been used to switch context, SYSTEM_USER returns the name of the impersonated context.
6,CURRENT_USER
Returns the name of the current user. This function is equivalent to USER_NAME().
Syntax
CURRENT_USER
Remarks
CURRENT_USER returns the name of the current security context. If CURRENT_USER is executed after a call to EXECUTE AS switches context, CURRENT_USER will return the name of the impersonated context. If a Windows principal accessed the database by way of membership in a group, the name of the Windows principal will be returned instead of the name of the group.
To return the login of the current user, see SUSER_NAME (Transact-SQL) and SYSTEM_USER (Transact-SQL).
参考文档:
https://msdn.microsoft.com/en-us/library/ms174427.aspx?f=255&MSPPError=-2147217396