【问题标题】:Sqlserver stored procedure to execute DML on behalf of another user代表另一个用户执行 DML 的 Sql Server 存储过程
【发布时间】:2015-06-15 04:13:50
【问题描述】:

要求:

用户A可以登录SS实例,但只能访问数据库X。用户A没有其他访问任何对象的权限。

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

数据库 X 或存储过程 ""sp_exec_dml" 是否需要访问其他数据库/对象。

例如

用户 A 执行

exec x..sp_exec_dml N"update z..table set ...................."

我希望这是有道理的。我来自 Oracle 背景,所以权限是如何授予的以及被授予者可能是谁令人困惑。

数据库或存储过程是否有权访问它们

谢谢

【问题讨论】:

    标签: sql sql-server dynamic permissions procedure


    【解决方案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 表示被授予者将获得指定的 允许。选择 Grant With 表示受让人也将 能够将指定的权限授予其他主体。

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

    存储过程利用所有权链接来提供 访问数据,使用户不需要有明确的权限 访问数据库对象。当对象存在所有权链 顺序访问的对象属于同一个用户。为了 例如,一个存储过程可以调用其他存储过程,或者一个 存储过程可以访问多个表。如果所有对象在 执行链具有相同的所有者,则 SQL Server 仅检查 调用者的 EXECUTE 权限,而不是调用者的权限 其他物体。因此,您只需要授予 EXECUTE 权限 存储过程;您可以撤销或拒绝所有权限 基础表。

    【讨论】:

      【解决方案2】:

      如果数据库 X 在

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

      那么用户应该有访问权限。

      【讨论】:

        猜你喜欢
        • 2013-03-26
        • 1970-01-01
        • 1970-01-01
        • 2012-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-01
        • 2014-01-07
        相关资源
        最近更新 更多