Ask a question about how to delete website data? -Php Tutorial

Source: Internet
Author: User
Tags how to delete website
Background: I suddenly deleted important things during the test one day. an important article immediately regretted it, but found that there was no "Recycle bin" and the data table was deleted physically, my heart is broken ...... No matter what you do, I will remember this profound lesson and leave it for myself... background: I suddenly deleted important things during the test one day. an important article immediately regretted it, but found that there was no "Recycle bin" and the data table was deleted physically, my heart is broken ......

No matter what you do, I will remember this profound lesson and leave a regret for myself.is_delField to indicate whether it has been deleted ......, All the deletions are not directly physical, and I am very scared to delete them again ......

But now I have encountered a problem. a field is a unique index, and I will delete it if I don't want to use this data for the time being. of course it is not actually deleted.is_delBut the problem is that the only field in the deleted row that I want to add already exists, as a result, I cannot add this line of data if I do not really delete it.

I came up with two solutions: I don't know whether the connection is unreasonable:

1: the data to be deleted is cut to another temporary table in the recycle bin"

2: only part of the data of the row to be deleted is cut. for example, the field with the unique index in the preceding section erased the current conflicting field data and placed it on another temporary table, you can use the primary key.

I always think that I have a problem with my ideas, but I don't know how to do it. I hope my experienced experts can give me some advice?

Reply content:

Background: I suddenly deleted important things during the test one day. an important article immediately regretted it, but found that there was no "Recycle bin" and the data table was deleted physically, my heart is broken ......

No matter what you do, I will remember this profound lesson and leave a regret for myself.is_delField to indicate whether it has been deleted ......, All the deletions are not directly physical, and I am very scared to delete them again ......

But now I have encountered a problem. a field is a unique index, and I will delete it if I don't want to use this data for the time being. of course it is not actually deleted.is_delBut the problem is that the only field in the deleted row that I want to add already exists, as a result, I cannot add this line of data if I do not really delete it.

I came up with two solutions: I don't know whether the connection is unreasonable:

1: the data to be deleted is cut to another temporary table in the recycle bin"

2: only part of the data of the row to be deleted is cut. for example, the field with the unique index in the preceding section erased the current conflicting field data and placed it on another temporary table, you can use the primary key.

I always think that I have a problem with my ideas, but I don't know how to do it. I hope my experienced experts can give me some advice?

If you want to optimize the solution, you can move it to another table. this will not affect the data in the current table, but will take advantage of the efficient work of the current table.
If the graph is convenient, you can set a composite indexis_delAlso included.

Generally, the unique index can only beid nicknameAnd other fields.

One recordis_delTimeid nicknameIf this is used, it is used and should not appear again.nicknameFor example, if this record is deleted, it should be banned rather than deleted normally.nicknameThis field should not be used again after it is deleted or banned.

Copy the recordRecycle binThe 'deleted data backup 'table can be used, but it is better to process your unique index and determine if you really need a unique index for this field.

Make a log system if you are not in trouble. all the added, deleted, and modified data is written into the log, and then perform rollback based on the log if any misoperation occurs.

Put it in another table. it is safe, and it may be faster when you query and delete data. However, I feel that when I temporarily delete a table, the id should be re-created. Otherwise, you may need to delete the data with the same id.

It is a good habit to retain the is_delete field when creating a table.
As you said, after you delete the data, you need to add a record that is the same as the unique index field of the deleted record. it can be seen that the deleted record should not be used in the business.
The solution I came up with is:
1. set the unique field and the is_delete field to a unique index. after adding this field, it is easy to restore the deleted record;
2. when inserting a unique duplicate record, move the deleted record to the history table. This type of original table is simpler, but it is troublesome to restore the previous record later;
3. if you insert a unique record, we recommend that you directly delete the record and move it to the history table. This makes it easy to insert it.

Does the recycle bin in windows avoid accidental deletion of important files?

I think you think too much about it. from the context of your story, you can see that your position is wrong. As a developer, you need to satisfy the customer's requirements. for example, you should not delete an article. if a user deletes something wrong, he will regret it, what is the relationship with you? It's like sending something here. can we retrieve it after deletion? Do developers need to be responsible for this?
Logs are actually very important, but they are usually used not to retrieve data, but to analyze the problem. In fact, mysql itself can also enable logs, which can help you retrieve data, why do I need to repeat it on php?
Therefore, my opinion is that unless the customer says that we often delete the wrong things when using it and do not perform physical deletion, we need to consider the is_del method at this time. However, we should also make it clear that the data will never be deleted after this method is used. never mind that there is another function that can delete the data marked as is_del, it still cannot solve the problem of frequent deletion of errors.

The program cannot solve the errors made by users, so there is no need to think too much at all. For some people, even if you have designed is_del1, is_del2, is_delN, the data deletion error will still occur.

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.