SQL Server: String vs Binary?

I have loading records for storage in a SQL Server 2008 database. Each of the records has a SHA-1 hash. Obviously, storing the SHA in String form will take 80 bytes compared to 20 if they are stored as bytes.

When querying a database that is better than SQL:

  • String comparison?
  • Binary comparison

I need help resolving the issue of how to store hashes, as it has a huge impact on the database. Thanks for any help.

+3
source share
2 answers

Use BINARY(20). No performance issues (this should be faster, if at all). There are minor inconveniences with values ​​such as the need to use byte[]instead stringin C #.

+2

HashBytes varbinary (8000), binary - http://msdn.microsoft.com/en-us/library/ms174415.aspx - SQL Server

+2

Source: https://habr.com/ru/post/1753091/


All Articles