Deleting SQL users in bulk



Is it possbile to delete SQL users (in bulk) in EPiServer. I can delete one by one but we have a lot of inactive users which I want to delete in bulk.

May be some sql query ? 

Dec 06, 2021 12:17

You could do it in a SQL query for sure but if it's an ongoing problem and you want to delete regularlly inactive users I'd suggest just build a scheduled job and doing it via code.

Dec 06, 2021 14:35

Thanks for your reply

Do you have any query to do it ?

It will not be an ongoing problem as we are moving to AD and no user would be create directly in EPiServer DB.

Dec 06, 2021 14:42

It's just SQL Membership, this is the structure to delete a single user by the unique identifer of the user. So just write a SQL script to pull the users out based on whatever criteria you want and run this for each

DECLARE @UserId uniqueidentifier
SET @UserId = 'GUID_for_UserId'
DELETE FROM aspnet_Profile WHERE UserID = @UserId
DELETE FROM aspnet_UsersInRoles WHERE UserID = @UserId
DELETE FROM aspnet_PersonalizationPerUser WHERE UserID = @UserId
DELETE FROM dbo.aspnet_Membership WHERE UserID = @UserId
DELETE FROM aspnet_users WHERE UserID = @UserId
Dec 06, 2021 14:47

Thanks a lot

Dec 06, 2021 14:48

If you want a DELETE with a WHERE clause: this is standard SQL.

What you can do is batch deletes like this:

SELECT 'Starting' --sets @@ROWCOUNT WHILE @@ROWCOUNT <> 0 DELETE TOP (xxx) MyTable WHERE ...

Or if you want to remove a very high percentage of rows...

SELECT col1, col2, ... INTO #Holdingtable
           FROM MyTable WHERE ..opposite condition.
INSERT MyTable (col1, col2, ...)
           SELECT col1, col2, ... FROM #Holdingtable


Dec 08, 2021 13:08

Is there any way to do it via UI / admin site ?  

Dec 10, 2021 15:36
Scott Reed - Dec 10, 2021 15:37
not that I'm aware of
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.