简体   繁体   English

数据库技术,用于编辑记录并确保在记录获得批准之前不更新记录

[英]Database technique for editing records and ensuring record is not updated until the record is approved

How would you handle a situation with the following scenario? 在以下情况下,您将如何处理情况?

You have a table with customer records with the following fields: 您有一个包含客户记录的表,其中包含以下字段:

id, name, email, phone
1, John, john@example.com, 515-222-3333
2, Smith, smith@example.com, 515-333-444

John opens his record and changes his phone number. 约翰打开记录并更改他的电话号码。 However, the actual record of the customer should not be changed until the admin approves the change. 但是,在管理员批准更改之前,不应更改客户的实际记录。

How would you handle a situation like this? 您将如何处理这种情况?

Would you? 你会?

a. Create an exact replica of customer table called customer-temp
b. Copy the record of John into customer-temp
c. let the admin review the updated record in customer-temp
d. once approved, the record is replaced with the record of john in customer table and remove John's record from customer-temp

Is this the best solution or is there a better way to handle this? 这是最好的解决方案还是有更好的方法来解决呢? Also what if customer table has a few other tables in relations? 如果客户表中还有其他一些表,该怎么办?

Expert advise would be appreciated. 专家建议,将不胜感激。 FYI, i use Postgresql database. 仅供参考,我使用Postgresql数据库。

----- updated format --- -----更新格式-

I would have an additional attribute for each attribute that needs review. 对于每个需要审查的属性,我都会有一个附加属性。

In your example, the entries could be: 在您的示例中,条目可能是:

id, name, name_tmp, email, email_tmp, phone, phone_tmp

name would contain the approved name, name_tmp the name that has been edited by the user. name将包含批准的名称, name_tmp用户已编辑的名称。
Upon approval, the contents of name_tmp are copied to name . 批准后,将name_tmp的内容复制到name

That way you don't have any problems with foreign key relationships. 这样,您在外键关系方面就不会有任何问题。

If you really don't want the attributes in the main table, create a customer_temp table like you suggested with id as primary key and foreign key referencing customer . 如果您确实不希望在主表中使用该属性,请像您建议的那样创建一个customer_temp表,其中id为主键,外键引用customer The downside is that you need more joins in your queries that way. 缺点是您需要以这种方式在查询中添加更多联接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM