469,934 Members | 2,497 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Use decimal or varbinary data type?

I need to store 256 bit hash (SHA-2 alogrithmn) in one of the table's
primary key. I would prefer to use numeric data type rather varchar
etc.

* Decimal datatype range is -10^38 +1 to 10^38 -1. I can split my 256
bit hash into two decimal(38, 0) type columns as composite key
* I can store the hash as varbinary. I never used it and don't have
much understanding in terms of query writing complexities and dealing
it through ADO (data type etc.)

It would be heavy OLTP type of systems with hash based primary key
used in joins for data retrieval as well.

Please provide your expert comments on this.

Regards
Anil

Jul 19 '07 #1
1 3922
(an**********@gmail.com) writes:
I need to store 256 bit hash (SHA-2 alogrithmn) in one of the table's
primary key. I would prefer to use numeric data type rather varchar
etc.

* Decimal datatype range is -10^38 +1 to 10^38 -1. I can split my 256
bit hash into two decimal(38, 0) type columns as composite key
* I can store the hash as varbinary. I never used it and don't have
much understanding in terms of query writing complexities and dealing
it through ADO (data type etc.)

It would be heavy OLTP type of systems with hash based primary key
used in joins for data retrieval as well.
I don't see what purpose the kludge with decimal should serve. Would you
not be left with a lot of code that converts forth and back?

Isn't the hash always always 256 bits? In such case would not binary(32)
be a better choice than varbinary.

Using a binary as key should be relatively straight forward. Of course,
there is some cost due to the size of the key, but that would not be any
better with decimal.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Batista, Facundo | last post: by
25 posts views Thread by Lennart Benschop | last post: by
1 post views Thread by Gilad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.