加入收藏 | 设为首页 | 会员中心 | 我要投稿 东莞站长网 (https://www.0769zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – 如何为表值函数授予权限

发布时间:2020-12-26 03:46:51 所属栏目:MsSql教程 来源:网络整理
导读:我做得对吗? 我有一个返钱的功能…… CREATE FUNCTION functionName( @a_principal money,@a_from_date datetime,@a_to_date datetime,@a_rate float ) RETURNS money AS BEGIN DECLARE @v_dint money set @v_dint = computation_here set @v_dint = round(@

我做得对吗?

我有一个返钱的功能……

CREATE FUNCTION functionName( @a_principal money,@a_from_date
  datetime,@a_to_date datetime,@a_rate float )  RETURNS money AS BEGIN

  DECLARE @v_dint money   set @v_dint = computation_here
     set @v_dint = round(@v_dint,2)

  RETURN @v_dint    
END 
GO 
Grant execute on functionName to another_user 
Go

我只是想知道这是否可以转换为iTVF?

我试过这样做但是我收到了一个错误:

CREATE FUNCTION functionName ( @a_principal money,@a_rate float )  
RETURNS TABLE AS 
RETURN SELECT returnMoney = computation_here  
GO  
Grant execute on functionName to another_user  Go

错误:

Msg 4606,Level 16,State 1,Line 2
Granted or revoked privilege EXECUTE is not compatible with object.

这个函数使用如下:

update table_name set interest = functionName(col1,col2...) where...

提前致谢!

解决方法

标量函数需要EXECUTE权限,但是当您转换为表值函数时,所需的权限将更改为SELECT.

您现在必须GRANT SELECT ON functionName TO another_user;

从BOL开始:

Users other than the owner must be granted EXECUTE permission on a function (if the function is scalar-valued) before they can use it in a Transact-SQL statement. If the function is table-valued,the user must have SELECT permissions on the function before referencing it.

(编辑:东莞站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读