0

If I run Select * from fm_my_permissions(null,'database'), the UPDATE/INSERT/DELETE permissions are missing from the user. The user is mapped, shows up as owner, and I ran GRANT UPDATE/INSERT/DELETE to user, which says it ran successfully. But, that did not fix the problem.

Strangely, user may run a stored procedure with the same command, and it runs successfully. If executed directly on the table in Management Studio, it fails with the message that user does not have UPDATE permission.

I have checked for other Deny settings, particular Schema permissions, but cannot find anything. User says they have tried un-mapping and re-mapping user. It only is happening with 1 database and 2 users.

1 Answer 1

2

To examine the effective permissions on an object for a user, connect as or impersonate the user and run

with c as 
(
    SELECT concat(quotename(schema_name(schema_id)),'.', quotename(name)) fn
    from sys.objects o
    where o.is_ms_shipped = 0
)
Select * 
from  c
cross apply fn_my_permissions(c.fn,'OBJECT') p
where subentity_name = ''

Note that there is an edge case that will cause an object not to appear in this view, which is when the user running the query lacks VIEW DEFINITION on the target object, which you can work around by listing the objects before impersonating the target user, eg

DECLARE @objects table (fn nvarchar(255))
insert into @objects(fn)
SELECT concat(quotename(schema_name(schema_id)),'.', quotename(name)) fn
from sys.objects o
where o.is_ms_shipped = 0

execute as user='someuser';
    with c as 
    (
        SELECT * FROM @objects
    )
    Select * 
    from  c
    cross apply fn_my_permissions(c.fn,'OBJECT') p
    where subentity_name = ''
revert

And you can examine all the object, schema, and database grants like this:

select case when class_desc = 'OBJECT_OR_COLUMN' then schema_name(o.schema_id) + '.' + o.name
            when class_desc = 'DATABASE' then 'DATABASE'
            when class_desc = 'SCHEMA' then 'schema::' + schema_name(p.major_id)
            end name,
       o.type_desc, 
       u.name grantee,
       p.class_desc,
       p.permission_name,
       p.state_desc
from sys.database_permissions P
join sys.database_principals u
  on u.principal_id = p.grantee_principal_id
left join sys.objects o 
  on p.major_id = o.object_id
where class_desc in( 'OBJECT_OR_COLUMN', 'DATABASE', 'SCHEMA')
and p.major_id >= 0
6
  • Thank you for the additional ways to check.The problem is that I can see permissions to UPDATE/INSERT/DELETE are missing, but Granting them does not add them, and they are mapped as owners, as well. The Grant statement ran successfully according to the message, but it didn't add the permissions as it should. What could be causing this?
    – Laura
    Commented Mar 10, 2022 at 21:48
  • Add additional details to your question in the form of the queries you have run and the results returned that outline the situation. Eg "mapped as owners" of what? What are the databases, schemas, and users involved. If possible create an isolated repro of the issue. Commented Mar 10, 2022 at 21:53
  • User wants to update a table B in database A. He tried to run: Update A.B SET column1 = '0'. This fails with the message user does not have update permissions. Next user creates a stored procedure with the same update query. It runs successfully. Why is this happening?
    – Laura
    Commented Mar 11, 2022 at 13:19
  • I first looked at the properties under his LOGIN. In User Mapping, he is mapped to database A as owner. Then I looked under database A Users. Under Membership he shows up db_owner. Under Securables and Schemas nothing is marked. We ran SELECT * FROM fn_my_permissions(null, 'database'). The result was missing "DELETE, UPDATE, and INSERT".
    – Laura
    Commented Mar 11, 2022 at 13:19
  • So next I ran GRANT Delete to Joe; GRANT INSERT to Joe; GRANT UPDATE to Joe. This ran successfully, We ran SELECT * FROM fn_my_permissions(null, 'database'), and these three permissions are still missing, and he still cannot run an update on the table in the database. I am not a dba, but have worked with the architecture side for years, and can feel my way around the admin side. I have never seen this before and would like some insight into what hidden DENY or conflict of logins or permissions could be causing this.
    – Laura
    Commented Mar 11, 2022 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.