June 19, 2012 at 2:50 pm
All,
Please help or advise.
I need a script to delete a login which is mapped(user mapping) to several databases.
Does anyone have it? Or is there any other way that I can do this.
Thanks in advance,
SueTons
June 19, 2012 at 3:04 pm
something like this should be pretty close:
if you cannot drop a database user because it is the object owner, this would rroll it back so you can fix that first.
SET XACT_ABORT ON
BEGIN TRAN
DECLARE @UserToDelete varchar(50);
exec sp_msForEachDB '
USE [?];
IF EXISTS (SELECT * FROM [?].sys.database_principals WHERE name = N''myDomain\Lowell'')
DROP USER [myDomain\Lowell];';
IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'myDomain\Lowell')
DROP LOGIN [myDomain\Lowell];
COMMIT TRAN
Lowell
June 19, 2012 at 3:11 pm
Lowell (6/19/2012)
something like this should be pretty close:if you cannot drop a database user because it is the object owner, this would rroll it back so you can fix that first.
SET XACT_ABORT ON
BEGIN TRAN
DECLARE @UserToDelete varchar(50);
exec sp_msForEachDB '
USE [?];
IF EXISTS (SELECT * FROM [?].sys.database_principals WHERE name = N''myDomain\Lowell'')
DROP USER [myDomain\Lowell];';
IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'myDomain\Lowell')
DROP LOGIN [myDomain\Lowell];
COMMIT TRAN
Thanks Lowell for the quick reply. I will try it.
SueTons.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply