Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:19:01+00:00 2026-05-31T18:19:01+00:00

We separate features in our database using schemas. For example, all Create & Maintain

  • 0

We separate features in our database using schemas. For example, all Create & Maintain Value (CMV) objects live within the CMV schema. Of course, each schema uses objects like stored procedures, views, functions etc.

I want to create a set of database roles by schema to use for security purposes. For example:

db_datareader 
db_datawriter 
cmv_executor //for stored procs and functions
cmv_viewer   //for views

So my question is:

How do I GRANT EXECUTE (or whatever) for various views, functions and stored procedures (etc.) by schema and bundle them up into a single role without running each GRANT by hand?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:19:02+00:00Added an answer on May 31, 2026 at 6:19 pm

    Schema permissions

    -- execute permission on programmability objects in CMV schema
    GRANT EXECUTE ON SCHEMA::CMV TO cmv_executor
    -- DML permissions on tables/views in CMV schema
    GRANT SELECT, INSERT, UPDATE, DELETE ON SCHEMA::CMV TO cmv_viewer
    

    This should eliminate the need for adding users to db_datareader and db_datawriter roles unless users need read/write for objects in schemas other than CMV.

    See here for more information on granting schema permissions.

    Object permissions

    -- use output of this query to grant permissions for individual objects
    SELECT
        'GRANT SELECT ON ' +
        QUOTENAME(SCHEMA_NAME(schema_id)) + '.' +
        QUOTENAME(name) + ' TO [cmv_viewer];'
    FROM
        sys.objects
    WHERE
        SCHEMA_NAME(schema_id) = 'CMV'
            AND
        type_desc = 'VIEW'
    UNION
    SELECT
        'GRANT EXECUTE ON ' +
        QUOTENAME(SCHEMA_NAME(schema_id)) + '.' +
        QUOTENAME(name) + ' TO [cmv_executor];'
    FROM
        sys.objects
    WHERE
        SCHEMA_NAME(schema_id) = 'CMV'
            AND
        type_desc IN ('SQL_STORED_PROCEDURE', 'SQL_SCALAR_FUNCTION',
                      'SQL_INLINE_TABLE_VALUED_FUNCTION');
    

    I didn’t include CLR functions or procedures, so add those if needed. Valid values for the type_desc column found here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Mybatis migration tool to maintain the schema to our database but
I´m trying to separate a gridViewColumn into two rows. Im using default style for
SHould I create a separate class for each object in an aggregate or should
first some data: we are using Oracle 11g databases. A primary database running on
Our software currently has many features. I've been asked to make a free trial
I'm using Ninject in an MVC project and I've used the autoregistration features in
I have starting using Mercurial for my (our) versioning needs. I have now come
Background Given that 'most' developers are Business application developers, the features of our favorite
We have a ton of features in our application that can be described very
Yahoo has separate map for India ( which has more details than the regular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.