Sqlserver存储过程代表另一个用户执行DML

时间:2015-06-15 04:13:50

标签: sql sql-server dynamic permissions procedure

要求:

用户A可以登录SS实例,但只能访问数据库X.用户A无法访问任何对象。

数据库X有一个stored_proc,名为" sp_exec_dml"它接受一个DML字符串并执行它。这个存储过程将(应该?)作为所有者X运行。

执行数据库X,或存储过程"" sp_exec_dml"然后需要访问其他dbs /对象。

例如

用户A执行

exec x..sp_exec_dml N"更新z..table设置..................."

我希望这是有道理的。我来自Oracle背景,所以如何授予权限以及受赠者可能会让他们感到困惑。

数据库或存储过程是否已授予他们访问权限

感谢

2 个答案:

答案 0 :(得分:1)

根据MSDN :(网址:https://msdn.microsoft.com/en-US/library/ms345484.aspx

  

授予存储过程的权限

In Object Explorer, connect to an instance of Database Engine and then expand that instance.

Expand Databases, expand the database in which the procedure belongs, and then expand Programmability.

Expand Stored Procedures, right-click the procedure to grant permissions on, and then click Properties.

From Stored Procedure Properties, select the Permissions page.

To grant permissions to a user, database role, or application role, click Search.

In Select Users or Roles, click Object Types to add or clear the users and roles you want.

Click Browse to display the list of users or roles. Select the users or roles to whom permissions should be granted.

In the Explicit Permissions grid, select the permissions to grant to the specified user or role. For a description of the permissions,
     

请参阅权限(数据库引擎)。

     

选择Grant表示受让人将获得指定的   允许。选择授予使用表示受让人也将   能够将指定的权限授予其他主体。

此链接还解释了一些概念: (网址:https://dba.stackexchange.com/questions/6878/sql-server-stored-procedure-permissions

  

存储过程利用所有权链提供   访问数据,以便用户不需要具有明确的权限   访问数据库对象。对象时存在所有权链   顺序访问彼此由同一用户拥有。对于   例如,存储过程可以调用其他存储过程,或者   存储过程可以访问多个表。如果所有对象都在   执行链具有相同的所有者,然后SQL Server只检查   调用者的EXECUTE权限,而不是调用者的权限   其他对象。因此,您只需要授予EXECUTE权限   存储过程;你可以撤销或拒绝所有权限   基础表。

答案 1 :(得分:0)

如果数据库X在

中有“table”
exec x..sp_exec_dml N"update z..table set ..................."

然后用户应该有权访问。

相关问题