简体   繁体   English

与表中的LastModifyOn(DateTime)列相比,使用rowversion(timestamp)有什么好处?

[英]What is the benefit of using rowversion(timestamp) over LastModifyOn(DateTime) column in a table?

Problem: 问题:

I am working on asp.net application and my Intention is to confirm that a table row is updating only when it is not updated in between a user's request and submit . 我正在asp.net应用程序上工作,目的是确认仅当在用户的请求和Submit之间未更新表行时 ,该表行才会更新

Scenario 情境

  1. User X and Y open same invoice(invoiceid=12) in different browser 用户X和Y在不同的浏览器中打开相同的发票(invoiceid = 12)
  2. User X changed invoice date to 1-july-2014 in UI. 用户X在UI中将发票日期更改为2014年7月1日。
  3. User Y changed invoice date to 5-july-2014 in UI 用户Y在用户界面中将发票日期更改为2014年7月5日
  4. User X press submit button.-- Invoice date changed to 1-july-2014 用户X按提交按钮。-发票日期更改为2014年7月1日
  5. User Y press submit button.-- Invoice date changed to 5-july-2014. 用户Y按提交按钮。-发票日期更改为2014年7月5日。

X and Y both did not know whether invoice data are not altered in between. X和Y都不知道两者之间的发票数据是否未更改。

Solution-1 解决方案1

  1. We added a column LastModifyOn(DateTime) in invoice table 我们在发票表中添加了列LastModifyOn(DateTime)
  2. When retrieve the invoice data for edit also getting LastModifyOn column data 当检索发票数据进行编辑时,还会获取LastModifyOn列数据
  3. Keeping the encrypted LastModifiedOn data in hidden field in UI 将加密的LastModifiedOn数据保留在UI的隐藏字段中
  4. When user submitting the invoice data changes, we also sending LastModifiedOn to compare. 当用户提交发票数据更改时,我们还将发送LastModifiedOn进行比较。
  5. Showing appropriate message. 显示适当的消息。

Solution-2 解决方案2

  1. We added a column version(rowversion) in invoice table 我们在发票表中添加了列版本(版本)
  2. When retrieve the invoice data for edit also getting version column data 当检索发票数据进行编辑时,还会获取版本列数据
  3. Keeping the encrypted version data in hidden field in UI 将加密的版本数据保留在UI的隐藏字段中
  4. When user submitting the invoice data changes, we also sending version to compare. 当用户提交发票数据更改时,我们还将发送版本进行比较。
  5. Showing appropriate message. 显示适当的消息。

X and Y knows whether invoice data are altered in between or not. X和Y知道之间是否更改了发票数据。

Question: 题:

Now my question is what benefit we will get by using version(rowversion) column over LastModifyOn(DateTime)... 现在我的问题是,通过使用LastModifyOn(DateTime)上的version(rowversion)列,我们将获得什么好处...

Point: 点:

  1. We are audit trailing in invoice table so last updated on data is already available. 我们正在对发票表进行审计跟踪,因此数据的最新更新已经可用。
  2. Please mention strong points in reason not like we do not need to update rowversion column explicitly or definition of timestamp .. 请提出要点,以免我们不需要显式更新rowversion列或timestamp的定义。

It looks as if you have decided (I might add, correctly) that timestamp/rowversion is better than datetime. 好像您已经确定(我可能会正确补充)时间戳/行版本比日期时间更好。 IMO it is up to you and the purpose. IMO取决于您和目的。 I will try to list down the differences between these two. 我将尝试列出这两者之间的差异。

  • timestamp range is from 1970-01-01 00:00:01 to 2038-01-19 03:14:07; 时间戳范围是从1970-01-01 00:00:01到2038-01-19 03:14:07; where as datetime range is from 1000-01-01 00:00:00 to 9999-12-31 23:59:59 日期时间范围从1000-01-01 00:00:00到9999-12-31 23:59:59
  • timestamp supports timezones where as datetime doesn't 时间戳支持datetime不支持的时区
  • timestamp is guaranteed to be unique (provided you use it properly) where as datetime is just a datatype and can be manipulated (specified in an insert for example) 时间戳保证是唯一的(前提是您使用得当),因为datetime只是数据类型,并且可以进行操作(例如,在插入中指定)

PS: From v2008 onwards 'timestamp' is deprecated, so use rownumber (they are synonyms)*. PS:从v2008开始,不建议使用“时间戳”,因此请使用rownumber(它们是同义词)*。

*Source: http://msdn.microsoft.com/en-us/library/ms182776.aspx *来源: http//msdn.microsoft.com/en-us/library/ms182776.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与向实体表中添加新字段相比,使用通用属性有什么好处 - What's the benefit with using generic attributes over adding new fields to an entity table 使用async从数据库返回数据有什么好处? - What's the benefit of using async to return data from database? 使用Telerik Grid Project或Telerik UI Project的额外好处是什么? - What is that extra benefit of using Telerik Grid Project Or Telerik UI Project 使用AsyncController有什么好处? - What is the benefit of usage AsyncController? 在使用EF的ASP.Net WebAPI方法中使用Async有什么好处? - What's the benefit with using Async in an ASP.Net WebAPI method with EF? 使用ShowHeaderFilterButton =“true”过滤ASPxGridView中的datetime列 - Filtering on a datetime column in ASPxGridView using ShowHeaderFilterButton=“true” 如何使用C#/ .NET将日期时间转换为时间戳(忽略当前时区) - How to convert datetime to timestamp using C#/.NET (ignoring current timezone) 使用HttpContext而不是HttpApplication有什么好处? - What is the advantage of using HttpContext over HttpApplication? 什么是收益?在 asp .NET 中使用收益有什么好处? - What is yield and what is the benefit to use yield in asp .NET? 在具有日期时间数据类型的列上使用 C# 对数据集进行排序 - Dataset Sorting using C# on a column with Datetime datatype
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM