从上述过程中找出谁在执行存储过程

时间:2022-11-13 11:02:26

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:

你可以在这篇非常有用的文章中读到更多:

#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:

你可以在这篇非常有用的文章中读到更多: