SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


The database principal owns objects in the database and cannot be dropped


The database principal owns objects in the database and cannot be dropped

Author
Message
zhazhuzhao
zhazhuzhao
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 69
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?

zhazhuzhao
zhazhuzhao
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 69
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

zhazhuzhao
zhazhuzhao
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 69
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

zhazhuzhao
zhazhuzhao
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 69
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_%'


zhazhuzhao
zhazhuzhao
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 69
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_%'


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search