BugNET

Open source issue tracking & project management
Welcome to BugNET Register | Login |

BugNET Forums

 
  Forum  Support  General Support  Script to delete users-
Previous Previous
 
Next Next
New Post 2/7/2008 4:12 AM
User is offline smoss
114 posts
www.orbitsolutions.co.za
5th Level Poster


Script to delete users- 
Modified By smoss  on 2/11/2008 1:07:04 AM)

Hi David,

I wrote the following SQL script to assign all calls for two certain users and move them to my Target user. After that the users are removed from the system.

---------------------------------------------------------------------------------------------------------
Old Script Removed
---------------------------------------------------------------------------------------------------------

I have two questions.

Firstly am I using the correct methodology??

Secondly why do I get this error


Server: Msg 547, Level 16, State 1, Line 99
DELETE statement conflicted with COLUMN REFERENCE constraint 'FK__aspnet_Us__UserI__30F848ED'. The conflict occurred in database 'bugnet', table 'aspnet_UsersInRoles', column 'UserId'.
The statement has been terminated.
Deleteing aspnet_UsersInRoles user

when executing this statement

Delete from aspnet_Users where  (UserID = @DeadUser2)

 
New Post 2/8/2008 8:15 AM
User is offline admin
658 posts
bugnetproject.com
1st Level Poster




Re: Script to delete users- 

From the looks of it there are still records in the aspnet_usersinroles table.  This table is not used any longer and you can delete any rows from it.


Davin Dubeau
BugNET - Core Developer

 
New Post 2/10/2008 11:30 PM
User is offline smoss
114 posts
www.orbitsolutions.co.za
5th Level Poster


Re: Script to delete users 
Modified By smoss  on 2/10/2008 11:31:24 PM)

This script is working:

Declare @TargetUser as varchar(40)
 Declare @DeadUser1 as varchar(40)

 -- TargetUser is going to replace the dead users
 Set @TargetUser = '{C339CD01-F20B-495B-BD66-376236D3A1AC}'


 -- This user is Outta Here
 set @DeadUser1 = '{FC356008-386C-4F9F-AE24-29429B797B2C}'


 -- Change the bugnet calls and history to one person

 -- REPORTERUser change
 print 'Deleteing bug''s reporteruserid'

 update bug set reporteruserid=@TargetUser where  (ReporterUserId = @DeadUser1)


 -- Assigned to change
 print 'Deleteing bug''s AssignedToUserId'

 update bug set AssignedToUserId=@TargetUser where  (AssignedToUserId = @DeadUser1)

 -- LastUpdateUserId

 print 'Deleteing bug''s LastUpdateUserId'

 update bug set LastUpdateUserId=@TargetUser where  (LastUpdateUserId = @DeadUser1)


 -- Now for the other tables

 -- UploadedUserID

 print 'Deleteing BugAttachment''s UploadedUserID'

 update BugAttachment set UploadedUserID= @TargetUser where  (UploadedUserID = @DeadUser1)

print 'Deleteing ProjectMailbox'

 update ProjectMailBox set AssigntoUserID= @TargetUser where  (AssigntoUserID = @DeadUser1)



 -- CreatedUserID
 print 'Deleteing BugComment''s CreatedUserID'

 update BugComment set CreatedUserID= @TargetUser where  (CreatedUserID = @DeadUser1)



 -- CreatedUserID
 print 'Deleteing BugHistory''s CreatedUserID'

 update BugHistory set CreatedUserID= @TargetUser where  (CreatedUserID = @DeadUser1)



 -- CreatedUserID
 print 'Deleteing BugNotification''s CreatedUserID'

 update BugNotification set CreatedUserID= @TargetUser where  (CreatedUserID = @DeadUser1)


 print 'Deleting BugTimeEntry'

 update BugTimeEntry set CreatedUserID= @TargetUser where  (CreatedUserID = @DeadUser1)


 -- Remove as users of the system
 print 'Deleteing userProjects user'

 Delete from userProjects where  (UserID = @DeadUser1)

 print 'Deleteing UserRoles user'
 Delete from UserRoles where  (UserID = @DeadUser1)




 -- Now remove ASP.NET Security records
 print 'Deleteing aspnet_membership user'

 Delete from aspnet_membership where  (UserID = @DeadUser1)


 print 'Deleteing aspnet_Profile user'

 Delete from aspnet_Profile where  (UserID = @DeadUser1)

  print 'Deleteing aspnet_UsersInRoles user'

 Delete from aspnet_UsersInRoles where  (UserID = @DeadUser1)

 print 'Deleteing aspnet_Users user'

 Delete from aspnet_Users where  (UserID = @DeadUser1)
 
Previous Previous
 
Next Next
  Forum  Support  General Support  Script to delete users-

Forum Policy

These Discussion Forums are dedicated to the discussion of the BugNET issue tracker.

For the benefit of the community and to protect the integrity of the project, please observe the following posting guidelines:
1. No Advertising.
2. No Flaming or Trolling.
3. No Profanity, Racism, or Prejudice.
4. Site Moderators have the final word on approving/removing a thread or post or comment.
5. English language posting only, please.