簡體   English   中英

鎖定表中記錄的正確/更好的方法是什么?

[英]What should be the correct/better approach for locking a record in table?

其實問題是這樣的:
付款,我在桌子上。 我提供了一些用於搜索,查看和編輯記錄的GUI。 現在,如果用戶正在嘗試 編輯記錄,請 執行某些特定操作,這需要1分鍾的時間來處理。 然后,另一個用戶將不能在同一記錄上執行該特定操作。

Traditional approach of doing this is, have a column in the table, say _isLocked_. and whenever user is performing that action it should change the value of said column to, say, true. Once the process is completed it should reset the value of the column. Also, just before someone tries to perform the action, it should check the value of the column and notifies the user if the record is locked.

還有什么其他方法可以做到這一點?

SELECT FOR UPDATE是方法。 通過使用此行為,我們可以得到這種行為。

正如Vinegar所說SELECT FOR UPDATE -接受他的回答,而不是我的:)

確保知道用戶何時真正想要編輯行以及何時完成。 根據您的應用程序,您可以打開一個單獨的窗口,用戶在該窗口中進行修改,然后確認/取消,因此您可以執行COMMIT / ROLLBACK。

並確保另一個試圖更改同一行的用戶不會遇到凍結的應用程序,而必須等待鎖定被釋放。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM