多个用户编辑数据库记录 [英] Editing database records by multiple users
问题描述
我设计了数据库表(在MS SQL服务器上标准化),并为应用程序创建了一个独立的Windows前端,供少数用户使用来添加和编辑信息。我们将添加一个网络界面,以便日后在生产区域进行搜索。
我担心如果两个用户开始编辑同一个记录,更新将是胜利者,重要信息可能会丢失。很多解决方案都在想,但我不确定是否会造成更大的头痛。
- 不要做任何事情,希望两个用户永远不会同时编辑同一个记录。
- 编辑例程可以存储原始数据的副本以及更新,然后比较用户何时完成编辑。
- 添加上次更新的DATETIME列,并在我们更新时检查它是否匹配,如果不是那么显示差异。
- 创建一个编辑表,用于记录用户何时开始编辑要检查的记录,并阻止其他用户编辑同一记录。 解决方案
如果您期望不常见的冲突, a href =http://msdn.microsoft.com/en-us/library/aa0416cz.aspx =nofollow noreferrer>乐观并发可能是您最好的选择。
Scott Mitchell撰写了关于实现该模式的综合教程:
实施乐观并发I have designed database tables (normalised, on an MS SQL server) and created a standalone windows front end for an application that will be used by a handful of users to add and edit information. We will add a web interface to allow searching accross our production area at a later date.
I am concerned that if two users start editing the same record then the last to commit the update would be the 'winner' and important information may be lost. A number of solutions come to mind but I'm not sure if I am going to create a bigger headache.
- Do nothing and hope that two users are never going to be editing the same record at the same time. - Might never happed but what if it does?
- Editing routine could store a copy of the original data as well as the updates and then compare when the user has finished editing. If they differ show user and comfirm update - Would require two copies of data to be stored.
- Add last updated DATETIME column and check it matches when we update, if not then show differences. - requires new column in each of the relevant tables.
- Create an editing table that registers when users start editing a record that will be checked and prevent other users from editing same record. - would require carful thought of program flow to prevent deadlocks and records becoming locked if a user crashes out of the program.
Are there any better solutions or should I go for one of these?
解决方案If you expect infrequent collisions, Optimistic Concurrency is probably your best bet.
Scott Mitchell wrote a comprehensive tutorial on implementing that pattern:
Implementing Optimistic Concurrency这篇关于多个用户编辑数据库记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!