SQL/MX 2.x Reference Manual (H06.04+)

SQL/MX Language Elements
HP NonStop SQL/MX Reference Manual540440-003
6-21
Character String Data Types
Considerations for Character String Data Types
Difference Between CHAR and VARCHAR
You can specify a fixed-length character column as CHAR(n), where n is the number of
characters you want to store. However, if you store five characters into a column
specified as CHAR(10), ten characters are stored where the rightmost five characters
are blank.
If you do not want to have blanks added to your character string, you can specify a
variable-length character column as VARCHAR(n), where n is the maximum number of
characters you want to store. If you store five characters in a column specified as
VARCHAR(10), only the five characters are stored logically—without blank padding.
When you are creating SQL/MP tables, group all variable-length columns after all
fixed-length columns for faster access. This practice also allows for more efficient use
of disk storage. For SQL/MX tables, the executor will put variable-length columns in the
most effective place.
Maximum Byte Length of a Character Column
The maximum length of a character column in an SQL/MP Format 1 table depends on
whether the data type is fixed-length or variable-length and on the file organization of
the file that contains the column. All SQL/MX tables are key-sequenced files.
Each variable-length character data item requires eight characters of storage for length
information, in addition to the space required for the data itself. As a result, the
maximum length for a variable-length column is less than the maximum length for an
otherwise equivalent fixed-length column.
A column that allows null requires two extra storage characters.
Collations and Character Sets
For SQL/MX Release 2.x, a character data type can be associated only with the
DEFAULT collation. You set the default NCHAR data type when you install NonStop
Data Type Key-Sequenced Entry-Sequenced
SQL/MP Format 1 tables:
Single-byte fixed-length 4061 4072
Single-byte variable-length 4059 4070
Double-byte fixed-length 2030 2036
Double-byte variable-length 2029 2035
SQL/MX tables:
Fixed-length 4040
*
Not applicable
Variable-length 4040
*
Not applicable
*The maximum row size is 4040 bytes, but the actual row size is less than that because of bytes used
by the header, null indicator, column length indicator, and other system features.