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

我做得对吗?

我有一个返钱的功能……

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.

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...