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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:14:24+00:00 2026-06-05T20:14:24+00:00

I have an app that allows users to upload large data files and then

  • 0

I have an app that allows users to upload large data files and then parses and stores the data in a SQL Server 2008 R2 database.

I would like to automatically run UPDATE STATISTICS on the table that the data is being imported in to since the users can run reports on the data and the amount of data is very large.

The data access is done through stored procedures and the user has no permissions on the tables, only execute on the stored procedures.

I wrote a stored procedure to take a table name and use sp_Executesql to run UPDATE STATISTICS on the table name that’s passed in. Both the stored proc and the table are owned by dbo. I get an error saying ‘Cannot find the object “table” because it does not exist or you do not have permissions.’ If I grant alter on the table to the user then it works fine but I’d like to avoid doing that. I thought that if the table and stored proc were owned by the same owner then the user’s permissions are ignored.

Is it possible to run UPDATE STATISTICS somehow without having the alter table permission?

  • 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-06-05T20:14:26+00:00Added an answer on June 5, 2026 at 8:14 pm

    The user’s permissions can’t be ignored if you use sp_executesql. Unless you make the procedure execute in the context of someone else. Rather than pick another user, I would rather create a user without a login. So let’s say you have a table called dbo.farb, that user foobarblat cannot ALTER (DENY isn’t necessary but it really proves the point):

    USE master;
    GO
    CREATE LOGIN foobarblat WITH PASSWORD = 'foobarblat', CHECK_POLICY = OFF;
    GO
    USE YourDatabase;
    GO
    CREATE USER foobarblat FROM LOGIN foobarblat;
    GO
    CREATE TABLE dbo.farb(id INT);
    GO
    DENY ALTER ON dbo.farb to foobarblat;
    GO
    

    Now let’s create a hidden user – we can give this user all the permissions in the world, because nobody can actually log in as this user, but for this example we can just grant ALTER on our table):

    CREATE USER SuperSecret WITHOUT LOGIN;
    GO
    GRANT ALTER ON dbo.farb TO SuperSecret;
    GO
    

    Now we can write a stored procedure that executes in the context of our SuperSecret user, but can be executed by foobarblat:

    CREATE PROCEDURE dbo.UpdateStats
        @tablename NVARCHAR(511)
    WITH EXECUTE AS 'SuperSecret'
    AS
    BEGIN
        DECLARE @sql NVARCHAR(MAX);
        SET @sql = N'UPDATE STATISTICS ' + @tablename;
        EXEC sp_executesql @sql;
    END
    GO
    GRANT EXEC ON dbo.UpdateStats TO foobarblat;
    

    Now connect in a new window using foobarblat – you should be able to execute this no problem:

    EXEC dbo.UpdateStats 'dbo.farb';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web-app that allows users to upload and download image files by
We have an asp.net application that allows users to upload files, the files are
I have a Rails app which allows users to upload Excel files which need
I have a rails 3 app that allows users to share files by uploading
I have a topics app that allows users to create topics. For each individual
We have a WPF app that allows our users to download encrypted content and
I have a SQL interface page in my classic ASP web app that allows
I have developed a small web app. This app allows users to upload images.
I have an Android app that allows the user to record data (such as
We have a desktop app that allows users to fill in a questionnaire. For

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.