您应该使用binary
数据类型。您可以使用binary
而不是,varbinary
因为散列函数将始终为相同类型的散列(例如,等)返回相同数量的MD5
字节SHA1
。这将减少管理可变长度二进制 ( varbinary
) 列所需的(少量)开销。
就制作它的大小而言,您可以运行此查询来检查每种散列类型的长度:
SELECT DATALENGTH(HASHBYTES('MD2', 'Testing')) AS [MD2Length],
DATALENGTH(HASHBYTES('MD4', 'Testing')) AS [MD4Length],
DATALENGTH(HASHBYTES('MD5', 'Testing')) AS [MD5Length],
DATALENGTH(HASHBYTES('SHA', 'Testing')) AS [SHALength],
DATALENGTH(HASHBYTES('SHA1', 'Testing')) AS [SHA1Length],
/* 2012 only: */
DATALENGTH(HASHBYTES('SHA2_256', 'Testing')) AS [SHA2_256Length],
DATALENGTH(HASHBYTES('SHA2_512', 'Testing')) AS [SHA2_512Length];
它应该是这样的:
MD2Length MD4Length MD5Length SHALength SHA1Length SHA2_256Length SHA2_512Length
--------- --------- --------- --------- ---------- -------------- --------------
16 16 16 20 20 32 64