December 9, 2013 at 2:15 pm
I'm trying to drop a user and am getting 'The database principal has granted or denied permissions to objects in the database and cannot be dropped. (Microsoft SQL Server, Error: 15284)'
I did
select user_name(grantor), object_name(id), *
from sysprotects (nolock)
where grantor = USER_ID ( 'the_user' )
to see what the object is, but object_name(id) is NULL
any ideas on the next move?
thanks
December 9, 2013 at 2:49 pm
this is the query i use for defining object ownership:
;with objects_cte as
(
select
o.name,
o.type_desc,
case
when o.principal_id is null then s.principal_id
else o.principal_id
end as principal_id
from sys.objects o
inner join sys.schemas s
on o.schema_id = s.schema_id
where o.is_ms_shipped = 0
and o.type in ('U', 'FN', 'FS', 'FT', 'IF', 'P', 'PC', 'TA', 'TF', 'TR', 'V')
)
select
cte.name,
cte.type_desc,
dp.name
from objects_cte cte
inner join sys.database_principals dp
on cte.principal_id = dp.principal_id
WHERE dp.name <> 'dbo'
order by dp.name
Lowell
December 9, 2013 at 2:51 pm
Did you tried querying sys.database_permissions?
select * from sys.database_permissions where grantor_principal_id = user_id ('USERNAME')
December 9, 2013 at 2:58 pm
thanks, but the user in question was not returned as an owner
I should also mention that the user is an orphan (that is, there is no associated login) - not sure if that is relevant or not
December 9, 2013 at 2:59 pm
and
select *, object_name(major_id) from sys.database_permissions where grantor_principal_id = user_id ('the_user')
returned NULL for object_name(major_id)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply