如何定义当前用户? [英] How to define a current user?

查看:164
本文介绍了如何定义当前用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以定义当前用户?

Is it possible to define a current user?

我找到了一个存储过程'sp_mgGetConnectedUsers'.它返回带有唯一字段地址"的结果集.如何将正在执行的查询与地址"相关联.

I found a stored procedure 'sp_mgGetConnectedUsers'. It returns a result set with the only unique field 'Address'. How could I associate an executing query with such 'Address'.

请咨询.

注意:据我了解,获取当前用户的另一种方法是为每个连接设置唯一的应用程序ID,但我不太喜欢这种方式.

Note: As far as I understand, another way to get the current user is to set a unique application Id for each connection, but I don't like this way much.

推荐答案

如果使用数据字典,则可以使用用户标量函数:

If using a data dictionary you can use the user scalar function:

select user() from system.iota;

并将其与从sp_mgGetConnectedUsers返回的DictionaryUser字段相关联.

and correlate that with the DictionaryUser field returned from sp_mgGetConnectedUsers.

如果不使用字典,最简单的方法是使用sp_SetApplicationID和sp_GetApplicationID.你为什么不喜欢这种方式?如果我们知道您的最终目标是什么,可能会更容易为您提供帮助.如果只想查看与查询关联的用户,请执行sp_GetSQLStatements过程.

If not using a dictionary the easiest way would be to use the sp_SetApplicationID and sp_GetApplicationID. Why don't you like that way? It might be easier to help you if we knew what your final goal was. If you just want to see the user associated with a query, execute the sp_GetSQLStatements procedure.

这篇关于如何定义当前用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆