May 3, 2013 at 12:57 am
Hi guys, Recently we got this error:
The database principal owns objects in the database and cannot be dropped.
The database version is SQL Server 2008,
I have checked that user doesn't have schema,procedure,function,table,view and so on.
My question is: how to check the user's objects?
May 3, 2013 at 1:45 am
Anyone can help is very appreciate!
Thanks!
May 3, 2013 at 5:21 am
this blog has a good explanation and the scripts to track down the offending schema:
Lowell
May 3, 2013 at 5:37 am
Can't remember where I found it, use this script to determine which objects are owned by the user
;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 = 'user_name'
Use this script to change the owner to dbo
alter authorization on object_name to dbo
May 4, 2013 at 4:23 am
Even i had faced the same issue but user was a database owner in my case, so i tried like
changing EXEC Sp_changedbowner 'SA' and tried dropping the user it worked.
We may need to give ownership to other user of objects or database to other before deleting the object owner
May 5, 2013 at 8:01 pm
SQLSACT (5/3/2013)
Can't remember where I found it, use this script to determine which objects are owned by the user
;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 = 'user_name'
Use this script to change the owner to dbo
alter authorization on object_name to dbo
Hi, I tried this sql and it returns no data! Also this database user is not a db_owner user!
Thanks all the same!
May 5, 2013 at 8:09 pm
Lowell (5/3/2013)
this blog has a good explanation and the scripts to track down the offending schema:
Hi, also I tried this way, and the sql didn't return data! I check that use didn't have schema!
Thanks all the same!
May 5, 2013 at 11:26 pm
zhazhuzhao (5/5/2013)
SQLSACT (5/3/2013)
Can't remember where I found it, use this script to determine which objects are owned by the user
;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 = 'user_name'
Use this script to change the owner to dbo
alter authorization on object_name to dbo
Hi, I tried this sql and it returns no data! Also this database user is not a db_owner user!
Thanks all the same!
Silly question - Are you executing the script against the correct database?
May 6, 2013 at 6:24 am
Are u sure there is no DB or schema connected to that user.
plz try this.
Use [Master]
select name, default_database_name from sys.sql_logins
go
Use [User_name]
select * from sys.user_token
May 6, 2013 at 6:43 am
Hi there,
Did you note the error number, that would help a lot to fix.
And Do you have the witness server, Run the script given above, that should fix.
thanks
May 7, 2013 at 2:21 am
Sure, I run it in the correct database!
SQLSACT (5/5/2013)
zhazhuzhao (5/5/2013)
SQLSACT (5/3/2013)
Can't remember where I found it, use this script to determine which objects are owned by the user
;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 = 'user_name'
Use this script to change the owner to dbo
alter authorization on object_name to dbo
Hi, I tried this sql and it returns no data! Also this database user is not a db_owner user!
Thanks all the same!
Silly question - Are you executing the script against the correct database?
May 7, 2013 at 2:26 am
Hi, I have run this script! I didn't find it has relation with that user I want to drop!
It's only a database user from windows domain login! The login has been droped!
suneet.mlvy (5/6/2013)
Are u sure there is no DB or schema connected to that user.plz try this.
Use [Master]
select name, default_database_name from sys.sql_logins
go
Use [User_name]
select * from sys.user_token
May 7, 2013 at 2:40 am
Hi, I got this error:
Msg 15183, Level 16, State 1, Line 1
The database principal owns objects in the database and cannot be dropped.
katukuri.sqldba (5/6/2013)
Hi there,Did you note the error number, that would help a lot to fix.
And Do you have the witness server, Run the script given above, that should fix.
thanks
June 17, 2013 at 8:12 pm
I use this script to find which object the user have:
select 'select * from ['+s.name+'].['+o.name+'] where ['+c.name +']=User_ID(''LoginName'')'
FROM sys.all_columns c
JOIN sys.all_objects o ON o.object_id = c.object_id
join sys.schemas s ON o.schema_id = s.schema_id
WHERE c.name LIKE '%principal_id%'
and o.name not like 'fn_%'
June 17, 2013 at 8:14 pm
zhazhuzhao (6/17/2013)
I use this script to find which object the user have:
select 'select * from ['+s.name+'].['+o.name+'] where ['+c.name +']=User_ID(''LoginName'')'
FROM sys.all_columns c
JOIN sys.all_objects o ON o.object_id = c.object_id
join sys.schemas s ON o.schema_id = s.schema_id
WHERE c.name LIKE '%principal_id%'
and o.name not like 'fn_%'
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply