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 284567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:28:10+00:00 2026-05-12T05:28:10+00:00

If I have a user that only has limited permissions – just db_datareader and

  • 0

If I have a user that only has limited permissions – just db_datareader and db_datawriter, which should only permit the user to query data and insert/edit/delete data, without allowing the user to add/modify/delete tables in the database.

There may be a need for the user to be able to execute stored procedures. If the user is given execute permissions (via the following sql: “GRANT EXECUTE TO UserName”), will the previous limitations (datareader and datawriter) still be enforced on what the user tries to execute through stored procedures? Or do Execute privileges really open up a pandora’s box of other security holes (and if so, what)?

  • 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-12T05:28:10+00:00Added an answer on May 12, 2026 at 5:28 am

    If the owner of the stored procedure has the rights to select, insert, update or delete against a table then select, insert, update and delete statements inside the stored procedure will execute as long as the caller has execute rights on the stored procedure, even if the caller does not have rights to directly perform select, insert, update or delete against the table.

    However a stored procedure can not perform DDL unless the caller has rights to perform DDL even if the owner of the stored procedure has DDL rights. Note this also applies to truncate table.

    Answer: In your case granting db_datareader and db_datawriter to a user already gives the user full DML on all tables. Granting execute on any stored procedure will not give any additional rights.

    Stored procedures can be used to increase data integrity by providing a gate through which all external programs must go. Do not grant insert, delete or update, but create SPs that do the work and enforce the appropriate rules about the data. (Above and beyond what can be done with constraints.) And as Joe Kuemerle points out, stored procedures can be used to increase security.

    I have observed this behavior while developing an application on SQL Server 2000 and this even re-tested on SQL Server 2008 and found the same behavior. I have not been able to find documentation on this behavior.

    Logged in as DBO and SA create a table:

    create table dbo.SO (PK int identity constraint SO_PK primary key
        , SomeData varchar(1000)
    )
    

    Then create some stored procedures for basic DML:

    create procedure dbo.InsertSO (@SomeData varchar(1000)) as
        begin
        insert into dbo.SO (SomeData) values (@SomeData)
        return SCOPE_IDENTITY()
        end
    go
    
    create procedure dbo.SelectSO (@PK int=null) as
        begin
        if @PK is not null
            select PK, SomeData from dbo.SO where PK = @PK
        else
            select PK, SomeData from dbo.SO
        end
    go
    
    create procedure dbo.CountSO as
        begin
        select COUNT(*) as CountSO from SO
        end
    go
    
    create procedure dbo.DeleteSO (@PK int=null ) as
        begin
        if @PK is not null
            delete dbo.SO where PK = @PK
        else
            delete dbo.SO
        end
    go
    
    create procedure dbo.UpdateSO (@PK int, @NewSomeData varchar(1000)) as
        begin`
        update dbo.SO
        set SomeData =  @NewSomeData
        where PK = @PK
        end
    go
    
    create procedure dbo.TruncateSO as
        begin
        truncate table dbo.SO
        end
    go
    

    As dbo, we can run the following SQL statements:

    declare @PK_to_update int
    insert into dbo.SO (SomeData) values ('Hello world!')
    set @PK_to_update = SCOPE_IDENTITY()
    
    declare @PK_to_delete int
    insert into dbo.SO (SomeData) values ('Goodbye cruel world!')
    set @PK_to_delete = SCOPE_IDENTITY()
    
    insert into dbo.SO (SomeData) values ('Four score and seven years ago...')
    
    select PK, SomeData
    from dbo.SO
    
    delete dbo.so
    where PK = @PK_to_delete
    
    update dbo.SO
    set SomeData = 'Hello Milky Way!'
    where PK = @PK_to_update
    
    select PK, SomeData
    from dbo.SO
    
    truncate table dbo.SO
    
    select COUNT(*) as CountSO from dbo.SO
    

    Or do the equivalent via the stored procedures

    go
    declare @PK_to_update int
    exec @PK_to_update = dbo.InsertSO 'Hello world!'
    
    declare @PK_to_delete int
    exec @PK_to_delete = dbo.InsertSO 'Goodbye cruel world!'
    
    exec dbo.InsertSO 'Four score and seven years ago...'
    
    exec dbo.SelectSO 
    
    exec dbo.DeleteSO @PK_to_delete
    
    exec dbo.UpdateSO @PK_to_update, 'Hello Milky Way!'
    
    exec dbo.SelectSO
    
    exec dbo.TruncateSO
    
    exec dbo.CountSO
    

    Now, create a DDL stored procedure and test:

    create procedure dbo.DropSO as
        begin 
        drop table dbo.SO
        end
    go
    begin transaction
    select TABLE_NAME from INFORMATION_SCHEMA.TABLES
    where TABLE_NAME = 'SO'
    exec dbo.DropSO
    select TABLE_NAME from INFORMATION_SCHEMA.TABLES
    where TABLE_NAME = 'SO'
    rollback transaction
    

    And now create another user and grant execute rights to all the stored procedure. Do not grant any other rights. (Assumes public does not have extra rights and mixed mode authentication. Mixed mode authentication is not recommended, but makes testing how rights are handled easier.)

    exec sp_addlogin @loginame =  'SoLogin' , @passwd = 'notsecure', @defdb = 'Scratch'
    
    exec sp_adduser @loginame = 'SoLogin', @name_in_db = 'SoUser'
    go
    grant execute on dbo.InsertSo to SoUser 
    grant execute on dbo.InsertSO to SoUser
    grant execute on dbo.SelectSO to SoUser
    grant execute on dbo.CountSO to SoUser
    grant execute on dbo.DeleteSO to SoUser
    grant execute on dbo.UpdateSO to SoUser
    grant execute on dbo.TruncateSO to SoUser
    grant execute on dbo.DropSO to SoUser
    

    Login in as SoLogin. Try the DML:

    declare @PK_to_update int
    insert into dbo.SO (SomeData) values ('Hello world!')
    set @PK_to_update = SCOPE_IDENTITY()
    
    declare @PK_to_delete int
    insert into dbo.SO (SomeData) values ('Goodbye cruel world!')
    set @PK_to_delete = SCOPE_IDENTITY()
    
    insert into dbo.SO (SomeData) values ('Four score and seven years ago...')
    
    select PK, SomeData
    from dbo.SO
    
    delete dbo.so
    where PK = @PK_to_delete
    
    update dbo.SO
    set SomeData = 'Hello Milky Way!'
    where PK = @PK_to_update
    
    select PK, SomeData
    from dbo.SO
    
    truncate table dbo.SO
    go
    select COUNT(*) as CountSO from dbo.SO
    go
    
    drop table dbo.so
    

    Nothing but errors:

    Msg 229, Level 14, State 5, Line 2
    The INSERT permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 229, Level 14, State 5, Line 6
    The INSERT permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 229, Level 14, State 5, Line 9
    The INSERT permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 229, Level 14, State 5, Line 11
    The SELECT permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 229, Level 14, State 5, Line 14
    The SELECT permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 229, Level 14, State 5, Line 14
    The DELETE permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 229, Level 14, State 5, Line 17
    The SELECT permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 229, Level 14, State 5, Line 17
    The UPDATE permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 229, Level 14, State 5, Line 21
    The SELECT permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 1088, Level 16, State 7, Line 24
    Cannot find the object "SO" because it does not exist or you do not have permissions.
    Msg 229, Level 14, State 5, Line 1
    The SELECT permission was denied on the object 'SO', database 'Scratch', schema 'dbo'.
    Msg 3701, Level 14, State 20, Line 2
    Cannot drop the table 'SO', because it does not exist or you do not have permission.
    

    Try the basic DML stored procedures:

    declare @PK_to_update int
    exec @PK_to_update = dbo.InsertSO 'Hello world!'
    
    declare @PK_to_delete int
    exec @PK_to_delete = dbo.InsertSO 'Goodbye cruel world!'
    
    exec dbo.InsertSO 'Four score and seven years ago...'
    
    exec dbo.SelectSO 
    
    exec dbo.DeleteSO @PK_to_delete
    
    exec dbo.UpdateSO @PK_to_update, 'Hello Milky Way!'
    
    exec dbo.SelectSO
    

    They work, because the owner of the SPs have the right rights, even though SoUser does not.

    Try the truncate or drop stored procedure:

    exec dbo.TruncateSO
    go
    exec dbo.DropSO
    

    Errors again:

    Msg 1088, Level 16, State 7, Procedure TruncateSO, Line 4
    Cannot find the object "SO" because it does not exist or you do not have permissions.
    Msg 3701, Level 14, State 20, Procedure DropSO, Line 4
    Cannot drop the table 'SO', because it does not exist or you do not have permission.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a system that only has one interpreter. Many user scripts come through
I have a requirement that a user is allowed only to enter string value
I have a user control that has a few public properties, one is an
I have a User table that has all of their avatars saved in an
I have a user that enters a piece of data into my database and
Let's say I have a user that entered 12 links into the database but
I have a user control that I've created, however when I go to add
I have a user model that requires the user to change their password every
I have a table (user) that contains user information. I have another table (userview)
I have a user control that takes a several seconds to load. Is there

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.