用于验证的 Sybase 哈希 +转换(varchar,...)?
我有一些表在流程中的一些最后步骤之后不应修改。
为了验证它没有进行任何修改(在最终状态之后),我正在考虑对所有列进行哈希。因此,对于每一行我:
- 将所有列创建一个varchar(其他数据类型被转换);
- 保存哈希结果
为了将来进行验证,我只需再次进行哈希并与之前获得的结果进行比较。
有更好的方法吗?
如果没有,当将其他数据类型转换为 varchar 时,我应该使用 convert(varchar, ...)
还是根据数据类型定义 varchar< 的长度/代码>?
I've some tables that shouln't be modified after some final steps in a process.
To validate that it wasn't made any modifications (after the final state) I'm thinking about making an hash of all the columns. So, for each row I:
- Make a varchar will all the columns (other data types are converted);
- Save the hash result
In the future, to validate, I simply do the hash again and compare with the result obtained previously.
Is there a better way to do it?
If not, when converting the other data types to varchar, should I use convert(varchar, ...)
or depending on the type of the data should I define a length to the varchar
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就我个人而言,如果我采用这种方法,我会使用时间戳字段而不是哈希值。每当该行发生任何事情时,这都会自动更新,并且比您所描述的要容易得多。
验证方法与您在问题中描述的方法类似。为了使审核变得容易,您可以使用触发器将时间戳值存储到另一个表中。
或者...说到触发器。如果您的真实意图是完全阻止更新,您可以使用触发器完全取消更新(除非它满足您设置的特定要求)。
这一切都假设您有理由不通过撤销所有用户的更新/删除权限来锁定表的权限。 (这将是最简单的)。
Personally if I were taking that approach I'd use a timestamp field instead of a hash. That will automatically update any time anything happens to the row and is a whole easier than what your describing.
The verification approach would be similar to what you describe in your question. To make auditing easy you could use a trigger to store the timestamp value off to another table.
Or... speaking of triggers. If your true intent is to block updates entirely you could use a trigger to cancel the update entirely (unless it meets specific requirements that you set).
This is all assuming you have a reason for not just locking down the rights on the table by revoking update / delete rights to all users. (which would be the easiest of all).