A user has records in different tables. How can this problem be solved?

Source: Internet
Author: User
At present, there is a function to delete users in the background. However, there are many functional modules, so you need to clear the records of users in multiple tables. {Code...} is it true to clear this information. Or is the deleted user information retained, but the user ID is not used for query ?? At present, there is a function to delete users in the background. However, there are many functional modules, so you need to clear the records of users in multiple tables.

// Clear all published articles and associated tags of the user // clear all followed tags of the user // clear all questions of the user // clear all answer // clear all credits of the user // clear all comments of the user // clear all favorites of the user // clear all questions of the user all private messages // clear all message notifications of the user // clear all drafts of the user // clear all invitation codes given to the user // clear all invitation answers of the user // clear the user's friend relationship // clear the user statistical table // clear the user's registration record ....

What do you usually do? Are you sure you want to clear this information. Or is the deleted user information retained, but the user ID is not used for query ??

Reply content:

At present, there is a function to delete users in the background. However, there are many functional modules, so you need to clear the records of users in multiple tables.

// Clear all published articles and associated tags of the user // clear all followed tags of the user // clear all questions of the user // clear all answer // clear all credits of the user // clear all comments of the user // clear all favorites of the user // clear all questions of the user all private messages // clear all message notifications of the user // clear all drafts of the user // clear all invitation codes given to the user // clear all invitation answers of the user // clear the user's friend relationship // clear the user statistical table // clear the user's registration record ....

What do you usually do? Are you sure you want to clear this information. Or is the deleted user information retained, but the user ID is not used for query ??

First, as mentioned above, try not to delete important data.
Second, if you do need to delete a master table, you can delete the table automatically. You only need to add a foreign key to the database and set it to on delete cascade.
When you delete data from the primary table, the foreign key automatically deletes the records that are deleted from the table. As long as the foreign key design is good. The master table deletes a piece of data, and a pile of data is deleted from the table ......

It is best to add a field in the table to identify whether the record is deleted.

Set a user ID field to delete the user ID. When searching, all personal data related to the user cannot be found, so there is no need to perform too many operations. For Statistics and the like, you can add a judgment on whether the user is available.

I think so too. Do not delete the data, but you may want it again that day. No ..

A thing is always right for her to delete.

Put it in a database transaction and delete it together

Refer to laravel's soft delete to add a field delete_at. The default value is null. The field is updated to the current time when it is deleted.

Do you dare to delete data ?! I have an alarm!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.