SQL Server : what is best datatype to store MD5 hash?

試著忘記壹切 提交于 2019-12-10 23:57:37

问题


I need to store in SQL Server a list of items uniquely identified by a hash.

In C# I compute my hash as MD5 hash of concatenation of the item ids ( Guid ).

Currently, my hash has datatype byte[] in C# , and binary(16) in SQL Server.

Here's the DDL :

CREATE TABLE [dbo].[ItemSet](
    [GUID] [uniqueidentifier] NOT NULL,
    [HashCode] [binary](16) NOT NULL,
    [Item1GUID] [uniqueidentifier] NOT NULL,
    [Item2GUID] [uniqueidentifier] NOT NULL,
    ...
    [UtcModified] [datetime] NULL,
 CONSTRAINT [ItemSet_PK] PRIMARY KEY CLUSTERED 
(
    [GUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

But perhaps I am better with :

[HashCode] [uniqueidentifer] NOT NULL,

uniqueidentifier is also 16 bytes and perhaps SQL Server offers performance or other advantages for uniqueidentifier over binary(16) ?

In C# the corresponding datatype is Guid and apparently there's a special Type 3 Guid form when calculated from an MD5 hash :

nnnnnnnn-nnnn-3nnn-xnnn-nnnnnnnnnnnn

where 3 indicates Type 3 , and the x byte is masked to 10xx.

But it's not clear to me how to create such a Type 3 Guid. And for my purposes it seems artificial & unnecessary to utilize a special format datatype.

Is there any optimal/accepted standard for working with MD5 hashes in C# and T-SQL ?

来源:https://stackoverflow.com/questions/49761364/sql-server-what-is-best-datatype-to-store-md5-hash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!