Different databases use different naming conventions for variable-length string datatypes. VARCHAR(n) or TEXT(n) are common naming formats for variable-length strings. Figure 3-6 shows variable-length strings on country names (COUNTRY), returning only the names of the countries and no padding out to maximum length as for fixed-length strings.
How should I understand out in the last sentence?
Answer
In addition to the correct answers given already it might be worth seeing an example of a padded out string, in a database context.
A variable length string, defined as VARCHAR(10)
and populated with ITALY
would return a string of length 5
containing the characters I
T
A
L
Y
. When treated as an array the variable length string would be char[5]
A fixed length string, declared as CHAR(10)
and populated with ITALY
would return a string of length 10 containing the characters I
T
A
L
Y
_
_
_
_
_
(where here on StackEchange I need to use '_' to denote a space). When treated as an array the fixed length string would be char[10].
With data like COLUMBIA
the variable length string would be C
O
L
O
M
B
I
A
while the fixed length string would be C
O
L
O
M
B
I
A
_
_
The fixed length string has been padded out with spaces at the end to ensure that it always takes up the defined number, in this case 10, of characters.
Many databases will allow you to use a function such as TRIM(yourString) to remove the padding spaces.
In both cases the maximum number of characters is adhered to so UNITED KINGDOM
would be saved as U
N
I
T
E
D
_
K
I
N
. VARCHAR(max)
or similar allows almost any size variable length string to be stored without truncation.
No comments:
Post a Comment