SELECT语句上的sql rowlock [英] sql rowlock on select statement

查看:273
本文介绍了SELECT语句上的sql rowlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.Net网页,用户可以在其中选择要编辑的行.我想在该行上使用行锁,并且当用户完成编辑并更新后,另一位用户可以编辑该行,即如何使用行锁,以便只有一个用户可以编辑行?

I have an ASP.Net webpage where the user selects a row for editing. I want to use the row lock on that row and once the user finishes the editing and updates another user can edit that row i.e. How can I use rowlock so that only one user can edit a row?

谢谢

推荐答案

您无法使用数据库引擎锁来锁定像这样的行.

You can't lock a row like that using DB engine locks.

大多数其他策略将依靠保持连接打开(例如sp_getapplock),这在Web应用程序中是荒谬的.

Most other strategies would rely on keeping the connection open (such as sp_getapplock) and this is nonsensical in web apps.

即使您在该行上设置了一个标志,如果用户只是简单地在编辑过程中关闭浏览器,会发生什么?

Even if you set a flag on the row, what happens if the user simply closes the browser mid-edit?

我建议使用时间戳/行版本列来检测其他会话中对该行的更改.

I'd suggest using a timestamp/rowversion column to detect changes to the row in other sessions.

这篇关于SELECT语句上的sql rowlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆