Suppose I have a column in a table which may hold information as short as a single char 'a' or as big as a huge binary chunk which translates to a jpg, png, mp3, whatever.
Which data type should I use for this?
I thought varbinary(max) or varchar(max), but will it occupy unused space if I just store a single char or a short string?
How is data stored when a field has a data-type that may have variable lengths?
According to this qa, https://dba.stackexchange.com/questions/1767/how-do-too-long-fields-varchar-nvarchar-impact-performance-and-disk-usage-ms, it shouldn’t matter, except for this:
Memory
If the client application allocates memory using the maximum size, the application would allocate significantly more memory than is necessary. Special considerations would have to be done to avoid this.
How do I know this? Sorry if I’m being dumb but it seems too vague.
What I would do if I were you, is using File-Stream enable database.
You can learn more about it here:
http://technet.microsoft.com/en-us/library/bb933993(v=sql.105).aspx
Also there are a lot of information in the net, so you should face no issues while using it.
Generally, you will have a table with many columns as you need and one column that will store the information in binary format or BLOB – Binary Large Object. The good thing is that the information that it can store depends only by your hard disk drive space, because it is store in your drive. In the other columns you can have a type field – for eaxmaple mp3/gpef/avi/etc that will help your application to convert this BLOB in its original type.