问题描述
是否可以模拟创建视图,类似于存储过程中的execute as"
?
Is it possible to create views with impersonation, similar to "execute as"
in stored procedures?
我想在单独的架构中创建一些视图.一些用户应该获得对这些视图的 SELECT
和 UPDATE
访问权限,以便他们能够更改基础表,但没有直接更新表的访问权限.
I would like to create some views in a separate schema. Some users should get SELECT
and UPDATE
access to these views, so that they are able to change the underlying tables, but without having direct update access to the table.
有视图可能吗?
推荐答案
不,这是不可能的.EXECUTE AS 主要与 SP 一起使用,但您可以更广泛地使用它们.来自 TechNet:
No, this is not possible. EXECUTE AS is mainly used with SP's, but you can use them a bit more widely. From TechNet:
在 SQL Server 中,您可以定义以下内容的执行上下文用户定义模块:函数(内联表值除外)函数)、过程、队列和触发器.
...
函数(内联表值函数除外)、存储过程、和 DML 触发器 { EXEC |EXECUTE } AS { CALLER |自我 |业主 |'用户名' }
Functions (except inline table-valued functions), Stored Procedures, and DML Triggers { EXEC | EXECUTE } AS { CALLER | SELF | OWNER | 'user_name' }
具有数据库范围 { EXEC | 的 DDL 触发器EXECUTE } AS { CALLER |自己|'用户名' }
DDL Triggers with Database Scope { EXEC | EXECUTE } AS { CALLER | SELF | 'user_name' }
具有服务器范围和登录触发器的 DDL 触发器 { EXEC |执行 }作为{来电者|自我 |'登录名' }
DDL Triggers with Server Scope and logon triggers { EXEC | EXECUTE } AS { CALLER | SELF | 'login_name' }
队列 { EXEC |EXECUTE } AS { SELF |业主 |'用户名' }
Queues { EXEC | EXECUTE } AS { SELF | OWNER | 'user_name' }
但是,您在这里有一些选择:
However, you have some options here:
- 创建返回数据的 GET-SP 和更新数据的 UPDATE-SP(为此我使用 XML 输入而不是表变量)
- 使用由您的模拟"用户创建的视图,并使用 DENY/GRANT 破坏权限继承,例如 GRANT VIEW DEFINITION
这篇关于SQL Server 视图中的模拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!