在更新数据时添加约束 [英] Add constrain in updating data

查看:82
本文介绍了在更新数据时添加约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,其中所有的会议都显示有时隙。在gridview中点击单元格,它会重定向到更新页面,用户可以更新时隙。我希望如果一个用户更新一个单元格而不是单元格不能由其他用户更新.....我怎么能在单元格上添加这样的约束....

I have a gridview in which all the meetings are displayed with time slot.On clicking cell in gridview it redirect to update page on which user can update time slot.i want that if one user updating one cell then than cell can not be updated by other user.....how can i add such constrain on cell....

推荐答案

在自动锁定表的事务中添加更新代码更新。

Add your updation code in transaction that automatically lock table while updating.
CREATE PROCEDURE [ProcedureName]
AS
BEGIN
  BEGIN TRANSACTION
  -- lock table "TableName" till end of transaction
  SELECT [ColumnNames]
  FROM [TableName]
  WITH (TABLOCK , HOLDLOCK)
  WHERE ...

  -- do some other stuff including insert/update table "TableName" 


  -- release lock
  COMMIT TRANSACTION
END 



TABLOCK将阻止其他会话的更新,您可以使用阻止更新和读取的TABLOCKX


这篇关于在更新数据时添加约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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