Saturday, February 7, 2015

Dropping a user from All SQL server databases

I Know its a simple thing, It is None other than sp_MSforeachdb. That is all you need to execute.

Below is a sample code:

EXECUTE master.sys.sp_MSforeachdb 'USE [?]; EXEC  sp_dropuser ''UserNameGoesHere'''

This will throw error messages for databases where user does not exist.

I was just too lazy to write the code to avoid the error since, it was doing the task.

Cheers.

No comments:

Post a Comment