by Remco Ros
5. February 2009 15:37
Method 1, using aspnet_Users_DeleteUser:
This stored procedure takes a bitmask parameter (@TablesToDeleteFrom). Set to 15 to remove all membership data for this user (including roles, profile, etc.):
1: DECLARE @RC int
2: DECLARE @ApplicationName nvarchar(256)
3: DECLARE @UserName nvarchar(256)
4: DECLARE @TablesToDeleteFrom int
5: DECLARE @NumTablesDeletedFrom int
6:
7: SET @ApplicationName = '/'
8: SET @UserName = 'userToDelete'
9: SET @TablesToDeleteFrom = 15
10:
11: EXECUTE @RC = [telashop].[dbo].[aspnet_Users_DeleteUser]
12: @ApplicationName
13: ,@UserName
14: ,@TablesToDeleteFrom
15: ,@NumTablesDeletedFrom OUTPUT
Method 2, remove directly from tables:
1: DECLARE @UserId uniqueidentifier
2: SET @UserId = 'THE GUID OF THE USER HERE'
3:
4: DELETE FROM aspnet_Profile WHERE UserID = @UserId
5: DELETE FROM aspnet_UsersInRoles WHERE UserID = @UserId
6: DELETE FROM aspnet_PersonalizationPerUser WHERE UserID = @UserId
7: DELETE FROM dbo.aspnet_Membership WHERE UserID = @UserId
8: DELETE FROM aspnet_users WHERE UserID = @UserId