SQL portability / CHAR and VARCHAR types |
Make sure that you have correctly defined the locale and length semantics for your character string data types.
When designing your database tables, consider using CHAR(N) for fixed-length string data (such as codes) and VARCHAR(N) for variable-length string data, such as names, address and comments.
Use VARCHAR variables for VARCHAR columns, and CHAR variables for CHAR columns to achieve portability across all kinds of database servers.
Avoid storing empty strings in VARCHAR columns, or make sure that your program is prepared to get nulls while the database stores empty strings.
Using byte or character length semantics depends mainly on the character set of your application. When using a single-byte character set, keep the default byte length semantics. When using a multibyte character set such as UTF-8, use character length semantics in both the database and the programs. The database column definition and the program variable definition must match, this can be simplified by using a database schema.