t-sql 创建用户并授予执行存储过程的权限

t-sql create user and grant execute on permission for stored procedures(t-sql 创建用户并授予执行存储过程的权限)
本文介绍了t-sql 创建用户并授予执行存储过程的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个创建数据库、存储过程、视图、表、udf 的脚本.我想包含一个脚本来创建用户user_1"并授予对数据库的执行权限.

I have a script which creates a database, stored procs, views, tables, udf. I want to include a script to create a user 'user_1' and give execute permission on the database.

我尝试按照以下步骤为所有存储的过程创建授权执行命令

I tried following to create grant exec command for all stored procs

declare @permission varchar(max)

select @permission = COALESCE(
    @permission + '; ' + 'Grant Execute on ' + name +  ' user_1', 
   'Grant Execute on ' + name +  ' user_1')
from sysobjects where xtype in ('P')

exec (@permission)

但是 exec (@permission) 不起作用.它给

But exec (@permission) does not work. It gives

';' 附近的语法不正确.

incorrect syntax near ';'.

我该如何解决这个问题?

How can I solve this?

推荐答案

创建登录:创建服务器级登录.然后...创建用户:让登录帐户附加到您的数据库.然后...授予执行至:授予对数据库中所有 sp 和函数的执行权限.如果您只想授予特定 sps 的权限,请使用Grant Execute ON abc TO xyz".

Create Login: creates the server level login. Then... Create User: lets the Login account attach to your database. Then... Grant Execute To: grants execute rights to ALL of the sp's and functions in your db. Use "Grant Execute ON abc TO xyz" if you only want to grant rights to specific sps.

Create login abacadaba with password='ABVDe12341234';
Create user abacadaba for login abacadaba;
Grant Execute to abacadaba;

这篇关于t-sql 创建用户并授予执行存储过程的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Number of working days between two dates(两个日期之间的工作日数)
How do I use dateadd to get the first day of last year?(如何使用 dateadd 获取去年的第一天?)
SQL- Count occurrences of a specific word within all stored procedures(SQL- 计算所有存储过程中特定单词的出现次数)
SQL query to make a column of numbers a string(使一列数字成为字符串的 SQL 查询)
T-SQL: Best way to replace NULL with most recent non-null value?(T-SQL:用最新的非空值替换 NULL 的最佳方法?)
Count days in date range with set of exclusions which may overlap(使用一组可能重叠的排除项计算日期范围内的天数)