Skip to main content
Suggested answer

Script to remove inactive GP accounts from all DBs in SQL Server

editSubscribe (0) ShareShare
ReportReport
Posted on by 15

Hi Community,

I am looking to make a script to remove all inactive GP accounts from all DBs in SQL server.  I have found on internet many different ways to do it but if somebody can send me an example of a tested script we can use it in our environment.

What I found so far is the following:

Remove user from a DB

SP_DROPUSER 'Useraccount'

ON MASTER DB

SP_DROPLOGIN 'Useraccount'

In the DYNAMICS DB

DELETE DYNAMICS..SY01400 WHERE USERID = 'Useraccount'
DELETE DYNAMICS..ACTIVITY WHERE USERID = 'Useraccount'
DELETE DYNAMICS..SY02000 WHERE USERID = 'Useraccount'
DELETE DYNAMICS..SY60100 WHERE USERID = 'Useraccount'

Is this correct?

The idea would be to create a script that gets the list of DBs where the useraccount currently is, and delete it from each of them.

If somebody can help me, I appreciate it.

Thank you,

Vanes2g

Categories: