以登录身份执行触发器

以登录身份执行触发器

运行触发器时可以模拟登录吗?

我可以跑execute as 'username',但不能execute as login='username'

我可以execute as这样使用

with EXECUTE AS  login='smr'
  select top 9 * from Phonelist.dbo.po
REVERT

我想把它放在触发器中,但我得到了语法错误。我的触发器看起来像

ALTER TRIGGER triggername ON TableName
with execute as login = "USER_A" 
AFTER INSERT AS 
BEGIN
DECLARE @var varchar(20)SELECT TOP 1 @var = columnname FROM DATABASE_B.dbo.TABLE_B
END

答案1

您正在寻找的语法ALTER TRIGGER命令是:

ALTER TRIGGER ON tableName WITH EXECUTE AS 'loginName'

相关内容