The EXECUTE permission was denied on the object 'xxxxxxx', database 'zzzzzzz', schema 'dbo'

后端 未结 14 1825
梦谈多话
梦谈多话 2020-12-02 05:18

I\'m having problems executing a function.

Here\'s what I did:

  1. Create a function using SQL Server Management Studio. It was successfully created.
14条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 05:27

    The general answer is to grant execute permission as explained above. But that doesn't work if the schema owner of SP is different to underlying objects.

    Check schema owners by:

    select name, USER_NAME(s.principal_id) AS Schema_Owner from sys.schemas s
    

    To change the owner of an schema you can:

    ALTER AUTHORIZATION ON SCHEMA::YOUR_SCHEMA TO YOUR_USER;
    

    Examples:

    ALTER AUTHORIZATION ON SCHEMA::Claim TO dbo
    ALTER AUTHORIZATION ON SCHEMA::datix TO user1;
    

    Finally if within your SP you are truncating a table or changing structure you may want to add WITH EXECUTE AS OWNER in your SP:

    ALTER procedure [myProcedure] 
    WITH EXECUTE AS OWNER
    
    as
    
    truncate table etl.temp
    

提交回复
热议问题