5

I have a load of records to store in a SQL Server 2008 database. Each of the records has a SHA-1 hash. Obviously storing the SHA in String form will take up 80 bytes compared to 20 if stored as Bytes.

When quering the database, which is SQL better at:

  1. Comparing Strings?
  2. Comparing Binary?

I need help deciding how to store the hashes as it has a huge storage impact on the database. Thanks for any help.

2
  • 1
    CHAR(40) only takes 40 bytes. Commented Jul 5, 2010 at 0:33
  • Thanks Marcelo - whould quering a record have better performance against Char than Binary? Commented Jul 5, 2010 at 0:38

2 Answers 2

3

Use BINARY(20). There are no performance issues (it should be faster, if anything). There are minor inconveniences with such values, such as the need to use byte[] instead of string in C#.

Sign up to request clarification or add additional context in comments.

Comments

2

HashBytes will return varbinary(8000), so I would definitely stick to binary - http://msdn.microsoft.com/en-us/library/ms174415.aspx - you'll be able to use it more easily in SQL Server

1 Comment

Thanks for posting this. It's become the new thing I've learnt today.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.