MySql、.NET、存储过程与调用客户端共享当前日期和时间
我正在编写一个存储过程来更新表:
UPDATE st SET somedate = NOW();
SP 的客户端必须知道 NOW 函数生成的确切日期和时间。
有两种选择:
1) 客户端将输入参数(称为 _now)传递给 SP,为其提供当前日期和时间
UPDATE st SET somedate = _now;
2) SP 将 NOW 的输出返回给客户端,并将其转换为输出参数
UPDATE st SET somedate = NOW();
SELECT somedate FROM st INTO _now;
您认为最好的是什么选项? 还有其他选择吗?
I'm writing a stored procedure to update a table:
UPDATE st SET somedate = NOW();
The client of the SP must know the exact date and time generated by the NOW function.
There are two options:
1) the client passes an input parameter (called _now) to the SP giving it the current date and time
UPDATE st SET somedate = _now;
2) the SP returns back the NOW's output to the client into an out parameter
UPDATE st SET somedate = NOW();
SELECT somedate FROM st INTO _now;
What do you think is the best option?
Are other options possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会做这样的事情:
i would do something like this:
我怀疑这两种方法都是错误的。
为什么?我怀疑您确实认为客户端必须能够识别受交易影响的记录 - 但使用时间戳来做到这一点是不准确的。问题不只是持续时间超过 1 秒的事务。同一秒内可能会发生两个这样的操作。
如果您有一组记录需要识别为属于某个组,那么必须在模式中表达它们 - 即使假设您从未对表进行进一步更新,大多数事务的时间戳显然也不可靠。
添加另一列或另一表并生成代理键来描述事务。
C.
I suspect that both approaches are wrong.
Why? I suspect you really men that the client must be able to identify the records affected by a transaction - but using a timestamp to do that will not be accurate. And its not just a transaction spanning more than 1 second that is the problem. Potentially two such operations may occur in the same second.
If you've got a set of records which you need to identify as belonging to some group then that must be expressed in the schema - the timestamp of the most transaction is obviously not reliable even assuming that you never have further updates on the table.
Add another column or another table and generate a surrogate key to describe the transaction.
C.