Am I able to find out who is executing the stored procedure from within that procedure?
我能从那个过程中找出谁在执行存储过程吗?
CREATE PROCEDURE
AS
BEGIN
DECLARE @executor
SET @executor = {query to find out}
END
1 个解决方案
#1
3
To achieve this you can use functions like
要实现这一点,可以使用以下函数
-
SUSER_NAME()
Function (it returns the login identification name of the user) MSDN article - SUSER_NAME()函数(它返回用户的登录标识名)MSDN文章。
-
CURRENT_USER()
(it returns the name of the current user) MSDN article - CURRENT_USER()(返回当前用户的名称)MSDN文章
-
USER_NAME()
(it returns a database user name from a specified identification number) MSDN article - USER_NAME()(它从指定的标识号返回数据库用户名)MSDN文章
-
ORIGINAL_LOGIN()
(it Returns the name of the login that connected to the instance of SQL Server.) MSDN article - (它返回连接到SQL Server实例的登录名)。MSDN文章
Example:
例子:
CREATE PROCEDURE
AS
BEGIN
DECLARE @executor
SELECT @executor = SUSERNAME()
...
END
You can read more in this very useful articles:
你可以在这篇非常有用的文章中读到更多:
-
Functions That Return User Names and User IDs
返回用户名和用户id的函数
-
Difference between ORIGINAL_LOGIN and SUSER_NAME
ORIGINAL_LOGIN和SUSER_NAME之间的差异
#1
3
To achieve this you can use functions like
要实现这一点,可以使用以下函数
-
SUSER_NAME()
Function (it returns the login identification name of the user) MSDN article - SUSER_NAME()函数(它返回用户的登录标识名)MSDN文章。
-
CURRENT_USER()
(it returns the name of the current user) MSDN article - CURRENT_USER()(返回当前用户的名称)MSDN文章
-
USER_NAME()
(it returns a database user name from a specified identification number) MSDN article - USER_NAME()(它从指定的标识号返回数据库用户名)MSDN文章
-
ORIGINAL_LOGIN()
(it Returns the name of the login that connected to the instance of SQL Server.) MSDN article - (它返回连接到SQL Server实例的登录名)。MSDN文章
Example:
例子:
CREATE PROCEDURE
AS
BEGIN
DECLARE @executor
SELECT @executor = SUSERNAME()
...
END
You can read more in this very useful articles:
你可以在这篇非常有用的文章中读到更多:
-
Functions That Return User Names and User IDs
返回用户名和用户id的函数
-
Difference between ORIGINAL_LOGIN and SUSER_NAME
ORIGINAL_LOGIN和SUSER_NAME之间的差异