Re: Grant Execute right to the group of users

From: Dan Guzman (danguzman_at_nospam-earthlink.net)
Date: 05/18/04


Date: Mon, 17 May 2004 19:41:50 -0500


> How could I grant the execute right to all stored procedures in a database
for a group of users ?

Below is a script that will grant execute permissions to the specified role
on all user procedures in the current database.

SET NOCOUNT ON

DECLARE @GrantStatement nvarchar(4000)

DECLARE GrantStatements CURSOR
LOCAL FAST_FORWARD READ_ONLY FOR
SELECT
    N'GRANT EXECUTE ON ' +
    QUOTENAME(ROUTINE_SCHEMA) +
    N'.' +
    QUOTENAME(ROUTINE_NAME) +
    N' TO Users'
FROM INFORMATION_SCHEMA.ROUTINES
WHERE
    OBJECTPROPERTY(
        OBJECT_ID(QUOTENAME(ROUTINE_SCHEMA) +
            N'.' +
            QUOTENAME(ROUTINE_NAME)),
        'IsMSShipped') = 0 AND
    OBJECTPROPERTY(
        OBJECT_ID(QUOTENAME(ROUTINE_SCHEMA) +
            N'.' +
            QUOTENAME(ROUTINE_NAME)),
        'IsProcedure') = 1
OPEN GrantStatements
WHILE 1 = 1
BEGIN
    FETCH NEXT FROM GrantStatements
        INTO @GrantStatement
    IF @@FETCH_STATUS = -1 BREAK
    IF @@FETCH_STATUS = 0
    BEGIN
        RAISERROR (@GrantStatement, 0, 1) WITH NOWAIT
        EXECUTE sp_ExecuteSQL @GrantStatement
    END
END
CLOSE GrantStatements
DEALLOCATE GrantStatements

-- 
Hope this helps.
Dan Guzman
SQL Server MVP
"Q" <anonymous@discussions.microsoft.com> wrote in message
news:0AF1C2FA-F089-4967-A89A-0793BA4F3D5E@microsoft.com...
> Hi all,
> How could I grant the execute right to all stored procedures in a database
for a group of users ?
>
> I create a database role called: "Users", and added the specific logins to
that group.  I grant them db_datareader and db_datawriter, so that they
could have access to all the data.  At this point, I don't know how to give
them execute permission to all stored procedures in the database.
>
> Thank You in advance,
> Q


Relevant Pages

  • Re: Execute Persmission denied on object sp_OACreate
    ... SQL Server doesn't check permissions on indirectly referenced objects as ... You can prevent ad-hoc execution of powerful master database procs while ... >I have a user who has execute permissions on a store procedure in a>database> which in turns executes 4 stored procedures in the master database. ...
    (microsoft.public.sqlserver.security)
  • Re: New user with no permissions can see and execute system stored procedures...
    ... Best regards ... But I can still see system views and stored procedures (though not system ... and map it to a database user and set its default schema to dbo. ... I have only tried to execute sys.sp_catalogs, but in my opinion a new ...
    (microsoft.public.sqlserver.security)
  • Re: how to secure a sql 2005 database?
    ... that's why i rather keep my stored procedures in my own source code, then pass it thru to sqlexec to execute. ... its like quickbooks turning over their internal structures, which they really don't, but provide an api to export data out. ... so are you saying that i can't create a user and make that user the only valid user to get into the database, and unless you know the password, even admins, you cant open the database at all. ...
    (microsoft.public.sqlserver.setup)
  • Re: Stored Procedures in the Master Database
    ... GRANTS must be done in the local database. ... The GRANT or the EXECUTE? ... >>> I have a stored procedure that I want to make available ...
    (microsoft.public.sqlserver.security)
  • Re: New user with no permissions can see and execute system stored procedures...
    ... map it to a database user and set its default schema to dbo. ... SQL Server Management Studio GUI) and execute _system_ stored procedures. ...
    (microsoft.public.sqlserver.security)