Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

The database principal owns objects in the database and cannot be dropped Expand / Collapse
Author
Message
Posted Tuesday, May 7, 2013 2:21 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 25, 2014 6:48 AM
Points: 9, Visits: 63
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?
Post #1450022
Posted Tuesday, May 7, 2013 2:26 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 25, 2014 6:48 AM
Points: 9, Visits: 63
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
Post #1450024
Posted Tuesday, May 7, 2013 2:40 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 25, 2014 6:48 AM
Points: 9, Visits: 63
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
Post #1450029
Posted Monday, June 17, 2013 8:12 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 25, 2014 6:48 AM
Points: 9, Visits: 63
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_%'

Post #1464437
Posted Monday, June 17, 2013 8:14 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 25, 2014 6:48 AM
Points: 9, Visits: 63
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_%'

Post #1464438
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse