AlanTsai
10/23/2015 - 6:44 AM

#Umbraco #sql delete user by user Id(用使用者Id刪除使用者)

#Umbraco #sql delete user by user Id(用使用者Id刪除使用者)

DECLARE @userId int;

SET @userId = $userId; -- set desire delete user Id

-- don't nuke these records, but can re-assign back to "admin" master user (or whoever else)
UPDATE umbracoNode SET nodeUser = 0 WHERE nodeUser = @userId
UPDATE cmsDocument SET documentUser = 0 WHERE documentUser = @userId
-- these can be nuked
DELETE FROM umbracoLog WHERE userId = @userId
DELETE FROM umbracoUser2App WHERE [user] = @userId
DELETE FROM umbracoUserLogins WHERE userID = @userId

-- 加入客制table

  --單位
  DELETE FROM UmbracoUser2Department WHERE UserId = @userId

  Delete FROM umbracoUser2Group WHERE UserId = @userId

	Delete FROM umbracoUserParm WHERE UserId = @userId
-- 結束加入客制table

DELETE FROM umbracoUser WHERE id = @userId
DECLARE @userId int;

SET @userId = $userId; -- set desire delete user Id

-- don't nuke these records, but can re-assign back to "admin" master user (or whoever else)
SELECT * from umbracoNode  WHERE nodeUser = @userId
SELECT * from cmsDocument WHERE documentUser = @userId

-- these can be nuked

SELECT * FROM umbracoLog WHERE userId = @userId
SELECT * FROM umbracoUser2App WHERE [user] = @userId

-- 加入客制table

	--單位
	SELECT * FROM UmbracoUser2Department WHERE UserId = @userId

	SELECT * FROM umbracoUser2Group WHERE UserId = @userId

	SELECT * FROM umbracoUserParm WHERE UserId = @userId

-- 結束加入客制table

SELECT * FROM umbracoUser WHERE id = @userId

把Umbraco user刪掉並且把本來屬於此user的資料(例如audit trail)指向admin(userid 0)

來源:Deleting Users