MS SQL datetime precision problem

后端 未结 7 1367
无人共我
无人共我 2021-01-05 11:37

I have a situation where two persons might work on the same order (stored in an MS SQL database) from two different computers. To prevent data loss in the case where one wou

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 11:56

    There is another way to do this potentially.

    Instead of passing in the "Last Saved" from the local machine, modify the UPDATE stored procedure. Assign LastSaved = getdate() Then return the value of LastSaved (and any other results, such as IDs), and update the LastSaved time at the client with that result.

    There are two obvious advantages to this. One is that your DateTime accuracy is preserved. The other is that the date and time are now consistent with the server, rather than suffering from any network latency and local clock drift issues.

    We usually use auto generated SPs for CRUD operations, and the tables usually run "Created/LastUpdated" and "CreatedBy/LastUpdatedBy" pairs where the dates are set on the server, and the "By" values are passed in, and if NULL are set to System_User

提交回复
热议问题