Skip to content

Instantly share code, notes, and snippets.

@bradleykronson
Last active June 23, 2026 15:50
Show Gist options
  • Select an option

  • Save bradleykronson/e7af52636210041ebc230d832680699d to your computer and use it in GitHub Desktop.

Select an option

Save bradleykronson/e7af52636210041ebc230d832680699d to your computer and use it in GitHub Desktop.
Delete Umbraco 17 user
DECLARE @UserId INT = 6; -- Replace with actual user ID
DECLARE @NewOwnerId INT = 4; -- Replace with ID of user to reassign content to (-1 = admin)
DECLARE @UserEmail NVARCHAR(255) = 'user@example.com'; -- Or find by email
DECLARE @UserKey NVARCHAR(255) = '881c7002-72e2-49c4-ac8c-467114d14dd6'; -- will be replaced in code below
-- Find user ID by email if needed
-- SELECT @UserId = id FROM umbracoUser WHERE userEmail = @UserEmail;
select @UserKey = [key] from umbracoUser WHERE id = @UserId;
BEGIN TRANSACTION;
-- REASSIGN CONTENT OWNERSHIP (prevents data loss)
UPDATE umbracoNode
SET nodeUser = @NewOwnerId
WHERE nodeUser = @UserId;
UPDATE umbracoContentVersion
SET userId = @NewOwnerId
WHERE userId = @UserId;
UPDATE umbracoContentVersionCultureVariation
SET availableUserId = @NewOwnerId
WHERE availableUserId = @UserId;
-- Remove user from user groups
DELETE FROM umbracoUser2UserGroup WHERE userId = @UserId;
-- Remove user login history
DELETE FROM umbracoUserLogin WHERE userId = @UserId;
-- Remove user start nodes
DELETE FROM umbracoUserStartNode WHERE userId = @UserId;
-- Remove external login tokens (if exists)
DELETE FROM umbracoExternalLogin WHERE userOrMemberKey = @UserKey;
-- Remove user data (if exists)
DELETE FROM umbracoUserData WHERE userKey = @UserKey;
-- Remove user log entries (THIS WAS MISSING)
DELETE FROM umbracoLog WHERE userId = @UserId;
DELETE FROM umbracoUser2ClientId WHERE userId = @UserId;
DELETE FROM umbracoUser2NodeNotify WHERE userId = @UserId;
-- Finally, remove the user
DELETE FROM umbracoUser WHERE id = @UserId;
-- Review before committing
COMMIT TRANSACTION;
-- ROLLBACK TRANSACTION;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment