sql服务器记录锁定 [英] sql server record locking

查看:155
本文介绍了sql服务器记录锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

团队,


如何查找已经使用的东西.

我的表中有n条记录,
如果用户A选择一条记录,则该特定记录应为锁
表示在用户A更新并且用户B必须收到消息记录已在使用"之前,其他用户才应该选择记录.

我正在使用Linq.

Linq或ADO.net

请帮帮我



在此先感谢


问候,

Manish Ahuja

Hi Team,


How to find inalready in use.

I have n number of records in my table,
if a userA select a record , the particular record should be lock
means the other users should not be able to select the record until the userA updates & User B Must get a message "Record already in use".

I am Using Linq.

Linq or ADO.net

Please help me



Thanks in Advance


Regards ,

Manish Ahuja

推荐答案

您可以在T-SQL中使用WITH(NOLOCK),例如.选择* FROM Table1 WITH(NOLOCK),然后接收到通过存储过程在ado.net中进行重新存储
You can use WITH(NOLOCK) in T-SQL eg. SELECT * FROM Table1 WITH (NOLOCK) and then recive that resaults in ado.net via stored procedure


我建​​议您研究一下SQL表锁定.您可以执行各种级别的锁定(例如,锁定整个表,锁定一行,完全不进行锁定).锁定的工作方式是,如果userA正在更新表,则userB将自动等待,直到userA完成.一旦userA完成,则userB将能够对该表执行查询.

如果要告诉用户记录已在使用中",则可以创建一个超时,一旦超时到期,就告诉用户该记录正在使用中.

或者,您可以通过在表中插入一条记录来创建自定义锁定解决方案,该记录指示您是否正在使用另一个表.使用完另一个表后,可以从锁定指示表中删除该记录.

话虽如此,这是您追求的最有可能的解决方案:

如果要在行级别指示记录是否被锁定,则表上可以有一列指示该行是否被锁定.锁定记录的代码将通过将其设置为"true"来更新"IsLocked"列.它将通过将其设置为"false"来解除锁定.用SQL表示布尔值的方法有很多种,但我最喜欢的是存储"yes"或"no"的varchar(3).
I suggest you look into SQL table locking. There are various levels of locking you can do (e.g., lock the whole table, lock a single row, do no locking at all). The way locking works is that if userA is updating the table, userB will automatically wait until userA is finished. Once userA finishes, userB will then be able to perform a query against that table.

If you want to tell the user "Record already in use", you could create a timeout and, once that timeout expires, tell the user that the record is in use.

Or, you could create a custom locking solution by inserting a record into a table that indicates whether or not you are using another table. When you are done with using the other table, you could then delete that record from the locking indication table.

All that being said, this is the most likely solution you''re after:

If you want to indicate at the row level if the record is locked, you could could have a column on the table that indicates if the row is locked. The code that locks the record will update that "IsLocked" column by setting it to "true". It will release the lock by setting it to "false". There are various ways of representing boolean values with SQL, but my favorite is a varchar(3) that stores "yes" or "no".


这篇关于sql服务器记录锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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