Is there any way to create a script to grant permissions to an object such as a stored procedure or table after the object has been created?

Posted on 2006-05-04
Last Modified: 2008-01-09
Basically going forward, is there a script that can be ran to grant execute rights to any stored procedure that is created without having to do it in each sp one by one.

For example:  I just created two stored procedures, now I would like to grant permission on those two after the fact.  One though is loop through the sysobjects table that is left joined by the syspermissions table;  gives me the list of stored procedures that currently do not have grant execute on and finally grant execute on those sp's.

The t-sql can look something like this:

select as sp_name
from syspermissions p
right join sysobjects o
on =
where o.xtype = 'P'
and not like 'dt%'
and p.grantee IS NULL

Any suggestions?

Question by:ktt2
    LVL 3

    Accepted Solution

    Two options I use most:

    select 'grant execute on ' + [name] + ' to userx'
    from sysobjects
    where xtype = 'P'
    and crdate > datediff(hh, -1, getdate())

    select 'grant execute on ' + o.[name] + ' to userx' as statement
    from syspermissions p
    right join sysobjects o
    on =
    where o.xtype = 'P'
    and not like 'dt%'
    and p.grantee IS NULL

    LVL 3

    Expert Comment

    Copy and paste the result in the query field and execute it again.

    The second option is a merge of your and my way ofcourse... ;)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now