Thursday, March 22, 2012

Drop Users

I know that there is a way to drop a user from one database but not from another. Does sp_drop user do that? To be more specific, I want to drop all users (except for dbo) from one database but not from all others. Is that possible.If you just want to revoke access for a specific database you can run sp_revokedbaccess 'Username'. You must have selected the database in Query Analyzer first.

/ Jonas|||Be sure to execute in quary analyzer and in the database from where you want to drop the users.

declare @.user_name as varchar(100)

DECLARE CUsers CURSOR FOR
SELECT name FROM MyTable..sysusers
where name <> 'dbo'

OPEN CUsers
FETCH FROM CUsers INTO @.User_Name

WHILE @.@.FETCH_STATUS = 0
BEGIN
EXEC sp_dropuser @.User_Name
FETCH NEXT FROM CUsers INTO @.User_Name
END

No comments:

Post a Comment