在Sql Server 2000/2005中,我有一些NT用户组需要被授予访问数百个存储过程的权限。
有一个很好的简单方法吗?
答案 0 :(得分:4)
答案 1 :(得分:1)
这是我用来授予许多程序权限的脚本:
DECLARE @DB sysname ; set @DB = DB_NAME()
DECLARE @U sysname ; set @U = QUOTENAME('UserID')
DECLARE @ID integer,
@LAST_ID integer,
@NAME varchar(1000),
@SQL varchar(4000)
SET @LAST_ID = 0
WHILE @LAST_ID IS NOT NULL
BEGIN
SELECT @ID = MIN(id)
FROM dbo.sysobjects
WHERE id > @LAST_ID AND type = 'P' AND category = 0
SET @LAST_ID = @ID
-- We have a record so go get the name
IF @ID IS NOT NULL
BEGIN
SELECT @NAME = name
FROM dbo.sysobjects
WHERE id = @ID
-- Build the DCL to do the GRANT
SET @SQL = 'GRANT EXECUTE ON ' + @NAME + ' TO ' + @U
-- Run the SQL Statement you just generated
EXEC master.dbo.xp_execresultset @SQL, @DB
END
END
您可以修改select以获取更具体的存储过程组。