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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:11:53+00:00 2026-05-28T19:11:53+00:00

I have mssql2008 r2 sql server The problem: User has some column permissions on

  • 0

I have mssql2008 r2 sql server

The problem:
User has some column permissions on the table. He could update some of the columns of the table (not all). We need to create UPDATE statement so that it will not violate permissions.
Preferably without dynamic query.

Is there this ability in MSSQL server?

  • 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-28T19:11:54+00:00Added an answer on May 28, 2026 at 7:11 pm

    Without dynamic SQL (or dynamic query construction in the app or API layer)? I don’t think it will be very pretty. The UPDATE command doesn’t have any inherent knowledge of what permissions the user might have on the affected column(s). It is going to submit the query to the engine and hope for the best. If the user doesn’t have permissions on all the columns, it’s going to return an error, not try to circumvent that by altering the intended statement. I think this would actually be a very bad thing to continue with the update even though not all intended columns have been updated.

    That all said, I suppose you could do something like this, but it is not going to be pretty at all – in fact it will be a lot easier if you are not relying on database principals:

    DECLARE 
        @dpid INT = DATABASE_PRINCIPAL_ID(),
        @obj  INT = OBJECT_ID('dbo.foo'),
        @col  SYSNAME = N'bar';
    
    UPDATE dbo.foo SET bar = CASE 
      WHEN EXISTS -- check they've been granted UPDATE at column or table level:
      (
        SELECT 1 
          FROM sys.database_permissions AS dp
          INNER JOIN sys.objects AS o 
            ON dp.major_id = o.[object_id]
          LEFT OUTER JOIN  sys.columns AS c
            ON dp.minor_id = COALESCE(c.column_id, 0)
          WHERE dp.grantee_principal_id = @dpid
          AND o.[object_id] = @obj
          AND (c.name = @col OR c.column_id IS NULL)
          AND dp.[permission_name] = 'UPDATE'
          AND dp.[state] = 'G' -- GRANT
      ) 
      AND NOT EXISTS -- since DENY trumps GRANT, make sure that doesn't also exist:
      (
        SELECT 1
          FROM sys.database_permissions AS dp
          INNER JOIN sys.objects AS o
            ON dp.major_id = o.[object_id]
          LEFT OUTER JOIN  sys.columns AS c
            ON dp.minor_id = COALESCE(c.column_id, 0)
          WHERE dp.grantee_principal_id = @dpid
          AND o.[object_id] = @obj
          AND (c.name = @col OR c.column_id IS NULL)
          AND dp.[permission_name] = 'UPDATE'
          AND dp.[state] = 'D' -- DENY
    )
    THEN @bar ELSE bar END
    -- WHERE...
    ;
    

    This isn’t exactly what you’re asking for; technically it updates the column but sets it to itself (so it will still be indicated as an updated column in a trigger, for example) but it prevents the input from being applied to the table. I also did not check against permissions granted in ways other than an explicit GRANT UPDATE or DENY UPDATE to the specified user or role – for example GRANT ALL, or permissions inherited by AD group membership, can complicate this. Of course it is not going to be much fun at all to manage this if you have multiple columns to check.

    You may want to add other conditionals to the WHEN clause, e.g. to avoid the check for dbo (who ) or users you want to explictly bypass the check, you could have:

    CASE 
      WHEN DATABASE_PRINCIPAL_ID() = 1 THEN @bar
      WHEN SUSER_SNAME = 'some_user' THEN @bar
      WHEN (...stuff from above...)
      ELSE bar
    END
    -- WHERE...
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have you ever seen any of there error messages? -- SQL Server 2000 Could
I have a table with 6 columns containing HTML content with some markups in
I have a database which has an orders table and inventory table. The order-items
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
I have a VB6 application accessing a single table on a MSSQL2000 server via
Extreme newbie question. I have my database (SQL Server) set up to cascade deletes
I have a table with this structure: [ID] [int] IDENTITY(1,1) NOT NULL, [ParentID] [int]
I have a php script which accesses a MSSQL2005 database, reads some data from
I have the following table in MSSQL2005 id | business_key | result 1 |
I have a database for an E-commerce storefront. MSSQL 2008. I have a table

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.