Data Types of fixed-length (char) and variable-length (varchar) characters
Char [(n)]
Character data with a fixed length of n Bytes and is not Unicode. N must be a value between 1 and 8,000. The storage size is n Bytes. The synonym for char in the SQL-92 is character.
Varchar [(n)]
Variable-length and non-UNICODE character data with a length of n Bytes. N must be a value between 1 and 8,000. The storage size is the actual length of the input data bytes, rather than n Bytes. The length of the input data can be zero. The synonym for varchar in the SQL-92 is Char varying or character varying.
Char is of a fixed length, so it is much faster than varchar! HoweverProgramIt is a little troublesome to handle. We need to remove spaces on both sides using functions such as trim!
Note
If n is not specified in the data definition or variable declaration statement, the default length is 1. If n is not specified by the cast function, the default length is 30.
The default database sorting rules will be assigned to objects using Char or varchar unless a specific sorting rule is assigned to the Collate clause. This sorting rule controlsCodePage.
For websites that support multiple languages, Unicode nchar or nvarchar data types should be considered to minimize character conversion issues. If Char or varchar is used:
If you want the data values in the column to be close to the same size, use char.
If you want the data values in the column to be significantly different, use varchar.
If set ansi_padding is off when you execute create table or alter table, a char column defined as null will be processed as varchar.
When the collation code page uses double-byte characters, the storage size is still n Bytes. Depending on the string, the storage size of n Bytes may be less than n characters.