Professional Web Applications Themes

complex sql script? - Microsoft SQL / MS SQL Server

I need to write a script that a dbo can run against a database and it needs to do the following... Create a new Role 'ABC' Create another new Role 'DEF' Grant execute permissions to Role 'ABC' to all stored procs that begin with ABC. Grant execute permissions to Role 'DEF' to all stored procs that begin with DEF. Grant execute permissions to Role 'ABC' to stored procs that begin with DEF if it's being called by an ABC stored proc. Grant execute permissions to Role 'DEF' to stored procs that begin with ABC if it's being called by a ...

  1. #1

    Default complex sql script?

    I need to write a script that a dbo can run against a
    database and it needs to do the following...

    Create a new Role 'ABC'
    Create another new Role 'DEF'

    Grant execute permissions to Role 'ABC' to all stored
    procs that begin with ABC.

    Grant execute permissions to Role 'DEF' to all stored
    procs that begin with DEF.

    Grant execute permissions to Role 'ABC' to stored procs
    that begin with DEF if it's being called by an ABC stored
    proc.

    Grant execute permissions to Role 'DEF' to stored procs
    that begin with ABC if it's being called by a DEF stored
    proc.



    I've already sort of begun to write this script and have
    passed the creation of the new roles and am now drudging
    through the permission granting portion.

    I've created a cursor to loop through the sysobjects
    table to grab only stored procs. I check the first few
    characters of each stored proc name to see if it's a ABC
    or a DEF stored proc and grant permissions to it
    accordingly. Then I get the id of that stored proc and
    create another cursor to grab any dependent records in
    the sysdepends table with that id and grab the depid.
    With the depid I requery the sysobjects table to see if
    it's a stored proc and, if so, I grant execute
    permissions on it.

    I've come to the conclusion that there's someone out
    there with a better, less complicated solution to script
    out.

    I'm asking for help folks.

    Thanks in advance,
    Steve.

    Steve Guest

  2. #2

    Default Re: complex sql script?

    Answered in security.

    Please do not post the same question independently to multiple groups.
    It's better to cross-post as appropriate.

    --
    Hope this helps.

    Dan Guzman
    SQL Server MVP

    -----------------------
    SQL FAQ links (courtesy Neil Pike):

    http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
    http://www.sqlserverfaq.com
    http://www.mssqlserver.com/faq
    -----------------------

    "Steve Moreno" <com> wrote in message
    news:0b4b01c368e9$99de3090$gbl... 


    Dan Guest

  3. #3

    Default Re: complex sql script?

    If the owner of all stored procedures in you DB is the same (prefferably
    dbo), you only need to grant permissions on the top level (calling) SP.
    Look for 'ownership chain' in BOL.
    Note that if you are using dynamic sql in your code, it will break ownership
    chains.

    HTH

    "Steve Moreno" <com> wrote in message
    news:0b4b01c368e9$99de3090$gbl... 


    Amy Guest

Similar Threads

  1. Complex SQL?
    By Toni Van Remortel in forum MySQL
    Replies: 5
    Last Post: December 7th, 06:08 PM
  2. Complex objects get me down
    By Regal iT in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: October 9th, 11:08 PM
  3. Replies: 2
    Last Post: January 24th, 06:00 AM
  4. Help with a complex find script
    By Andrew in forum FileMaker
    Replies: 3
    Last Post: December 14th, 01:50 AM
  5. complex condition
    By Steve Gilbert in forum PERL Beginners
    Replies: 4
    Last Post: October 30th, 06:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139