TheBugSlayer
Programmer
Hi all. I have a script that's supposed to delete a number of users from all databases. But for some reason, it complains about
Msg 15151, Level 16, State 1, Line 1
Cannot drop the user 'UserXYZ', because it does not exist or you do not have permission.
User UserXYZ does exist, AND I am a sysadmin. The script is the modified version of one that I found online last week and it follows:
As for the risks of deleting all users, this is a clone of a development server that's going out of phase. I had proceed in the wrong order so now I just need to remove all users, create them at the server level with their default databases and let SQL take care of the SIDs, etc. 88 user databases, too tedius to do it manually.
Thanks for your help. This is a bit time-sensitive.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)
Msg 15151, Level 16, State 1, Line 1
Cannot drop the user 'UserXYZ', because it does not exist or you do not have permission.
User UserXYZ does exist, AND I am a sysadmin. The script is the modified version of one that I found online last week and it follows:
Code:
[b]
set nocount on
declare @dbname as varchar(80)
declare @server_name as varchar(20)
select @server_name = @@servername
declare rs_cursor CURSOR for select name from master.dbo.sysdatabases
where name not in ('model','master','msdb','tempdb','alert_db','mssecurity')
order by name
open rs_cursor
Fetch next from rs_cursor into @dbname
IF @@FETCH_STATUS <> 0
PRINT '...'
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'USE ' + @dbname
EXEC('USE ' + @dbname)
DROP USER UserABC
...
DROP USER UserXYZ
FETCH NEXT FROM rs_cursor INTO @dbname
END
CLOSE rs_cursor
deallocate rs_cursor
[/b]
As for the risks of deleting all users, this is a clone of a development server that's going out of phase. I had proceed in the wrong order so now I just need to remove all users, create them at the server level with their default databases and let SQL take care of the SIDs, etc. 88 user databases, too tedius to do it manually.
Thanks for your help. This is a bit time-sensitive.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)