At a glance, varchar and char are not quite different, aren’t they? but actually, they have a critical different that you must attend of it. First, the theory is varchar will remove all space (blank) character either behind or ahead of string, but char is not. Okay maybe you will think, actually it doesn’t need, does it?
If you will not join the 2 characters, it doesn’t matter whether you will use either varchar or char, but how about If I have this condition. I’d like to extend my string variable, but actually the data have already there. This extend variable also will update to related table. What should I do? This one is one of the solution that you could apply. The solution should be provide user field in your table, let’s say, user1, user2, user3, this one is solomon’s standard table design.
I create a buffer who will merge the current field with the user field. Let’s say, my current field is 30 characters length, and I’d like to extend it become 60 characters, so I will use the 30 characters length user field.
When I’d like to load the buffer again, my code should be this one
bbuffer.LongName = bxTable.CurrentField + bxTable.User1, and in my stored procedure, I’ll update the related table by this code,
select @CurrentField = CurrentField, @User1 = User1
from xTable
where ……
update table
set name = @CurrentField + @User1
where ……..
if your @CurrentField and @User1 datatype are varchar, and let’s say the value of @User1 is ‘ text text’, and the value of @CurrentField is ‘header front’, so when you merge it, the merge string will be ‘header fronttext text’, it should be ‘header front text text’.
It’s dangerous, isn’t it?
The first one (’header fronttext text’) will happen if I’m using varchar data type, and the last one will happen if I’m using char data type.
So, be careful to apply the data type.