Is it better to set an index (primary or secondary) on a varchar(x)
or varbinary(x)
column?
I wasn't sure it even mattered. However what I see online (Googled - varchar vs varbinary) is that varchar
is almost dead or being pushed to the way side. So is this better to index or something? Could it be the type of index?
Excellent scenario: Indexing email addresses ([edit] encrypted byte array {varbinary} or string equivalent {varchar})
Thanks
It seems that indexes on varbinary
is the worst thing ever. Am I reading this right?
It is better to create an index on varchar than varbinary. Varbinary is suitable for blobs but you can store strings in varbinary also. Such blobs are complementary to your actual data. Your own research lead to that conclusion also.
An email address can be entered by user in variety of formats - [email protected] or [email protected] etc. It is easier to store/extract such information in/from varchar field. Joe Enos is absolutely right that binary comparisons will be case-sensitive (comparing binary info) whereas varchar will be case-insensitive assuming that's how you have set up your DB and column collation. With varbinary, you'll also have to be careful about padding.
Varchar is alive and healthy. When you index varchar(100), try to use a non-clustered index. My general preference is to use a surrogate key in most situations as clustered index.