1. CharFixed length, maximum of n characters.
2. VarCharA variable string with a maximum length of n. (n is an integer, different database, maximum length n different) char and varchar differences: varchar char saves space, but is slightly less efficient than char. It is said that varchar is more space-saving than char because varchar is a mutable string, such as: Storing the string "ABC" with VARCHAR (5), consuming only 3 bytes of storage, and storing it with char (5), which consumes 5 bytes ("abc"). The fact that varchar is less efficient than char is because when the varchar data is modified, data migration (that is, redundant I/O) may occur because of different data lengths. Where Oracle's expression for this redundant I/O description is "Row migration" (row migration). Line migration (Row migration):
"When a row of records is initially inserted in a block, the row migration occurs because the update operation causes the rows to increase and the block's free space is completely full." In this case, Oracle will migrate the entire row of data to a new block, and Oracle will keep the original pointer of the migrated row pointing to the new block that holds the row data, which means that the row ID of the migrated rows will not change. "One explanation: block is the smallest data organization and management unit in Oracle, the data file disk storage unit, and
Minimum database I/O units (
that is, read and write are a block hit size, so if the block is not full, update the content length change of the varchar field, and update the length of the varchar field unchanged, I/O times are the same, there is no additional consumption, only when the block full, The additional I/O is present, so the performance difference between char and varchar performance is quite subtle and negligible in most cases, so the meaning of the "slightly" difference described above)。 So, my development experience is: "
instead of char with varchar, there's nothing to worry about .”。
3. NvarcharThe characteristics of nvarchar need to be compared with varchar. The difference between nvarchar and varchar is primarily in the way data is stored: 1). varchar
Storage by ByteData varchar (6), can store up to 6 bytes of data, for example: "hahaha", "abcdef" ...
Note: A Chinese character in the database of how many bytes, to see the Unicode encoding, such as: UTF8 on MySQL accounted for 3 bytes, SQL Server chinese_prc_ci_as accounted for 2 bytes ...2). Nvarchar:
Store by characterData nvarchar (6), can store up to 6 characters/Chinese data, for example: "haha haha", "abcdef" ... nvarchar (m) the actual byte length of the maximum storage =n*m (n is encoded) if nvarcha R stores the English characters, and the byte length of n is stored according to the encoding method. In other words, if
with
nvarchar store English characters, waste more than half of storage space....
Summary:
1. The performance gap between char and varchar is very small and can be considered negligible.
2. In large data volume applications, the use of char and nvarchar can lead to a large amount of wasted storage space.
Char, VARCHAR, NVARCHAR in Oracle