2

For some reason, I need to truncate the users table, but I don't want to remove the user with ID equal to 1.

Is there any way to do it?

1 Answer 1

8

No, you can't truncate a table and leave data in it at the same time. That would be a contradiction in terms.

You'll need to do a standard delete

DELETE FROM users WHERE uid NOT IN (0, 1)

(it's important to make sure the anonymous user, ID 0, remains there too).

If you use the direct approach, be 100% sure that you know what you're doing. Unless you know different, there will probably be related data that doesn't get cleared out by simply removing an entry from the users table.

The best way to delete users is through the API: user_delete_multiple()

2
  • drush user-cancel would also be good, wouldn't it?
    – Mołot
    Aug 19, 2015 at 11:21
  • For individual accounts definitely @Mołot, but you'd need to script something to delete all and exclude the important ones
    – Clive
    Aug 19, 2015 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.