In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Type length description length shows that char (n) fixed length index is efficient, the program uses trim to remove excess white space n must be a value between 1 and 8000, the storage size is n bytes varchar (n) variable length efficiency is not as flexible as char n must be a value between 1 and 8000. The storage size is the actual length of bytes of input data instead of n bytes text (n) variable length non-Unicode data without specified length nchar (n) fixed length processing Unicode data type (all characters are represented by two bytes) the value of n must be between 1 and 4000 Storage size twice n bytes nvarchar (n) variable length processing unicode data type (all characters are represented by two bytes) the value of n must be between 1 and 4000. The storage size of bytes is twice the number of characters entered. The input data character length can be zero ntext (n) variable length processing unicode data type (all characters are represented by two bytes) without referring to length
Generally speaking, use nchar/nvarchar for Chinese characters and char/varchar for pure English and numbers
Char, it is very convenient to store fixed-length data, and the index on the char field is more effective, such as defining char (10), then no matter whether your storage is data up to 10 bytes or not, it takes up 10 bytes of space, and insufficient spaces are automatically filled, so trim () may be used many times in reading time.
Varchar. Store variable-length data, but not as efficiently as char. If the possible value of a field is not fixed length, we only know that it cannot exceed 10 characters, and it is most cost-effective to define it as varchar (10). The actual length of the varchart type is the length of its value + 1. Why "+ 1"? This byte is used to keep the actual length used. From the perspective of space, it is appropriate to use varchar; from the perspective of efficiency, it is appropriate to use char. The key is to find the tradeoff point according to the actual situation.
Text. Text stores variable length non-Unicode data with a maximum length of 2 ^ 31-1 (2147483647) characters.
Nchar, nvarchar, ntext. These three are more "N" in terms of name than the previous three, which means that characters of the Unicode data type are stored. We know that in characters, only one byte of English characters is enough to store, but there are many Chinese characters that need two bytes of storage. It is easy to cause confusion when English and Chinese characters exist at the same time. The Unicode character set is created to solve the incompatible problem of the character set. All its characters are represented by two bytes, that is, English characters are also represented by two bytes. The length of nchar, nvarchar is between 1 and 4000. Compared with char and varchar, nchar and nvarchar can store up to 4000 characters, whether in English or Chinese characters, while char and varchar can store up to 8000 English characters and 4000 Chinese characters. It can be seen that when using nchar and nvarchar data types, don't worry about whether the input characters are English or Chinese characters, which is more convenient, but there is some loss in the quantity when storing English.
So generally speaking, if it contains Chinese characters, use nchar/nvarchar, if pure English and numbers, use char/varchar
The differences between them are summarized as follows:
Char, nchar fixed length, high speed, large space, need to be dealt with
Varchar, nvarchar, text with variable length, small space, slow speed, no need to deal with
Nchar, nvarchar, ntext deal with Unicode code
Varchar uses a single byte to store data in SQL, nvarchar uses Unicode to store data, Chinese characters stored in SQL will be saved as two bytes (usually encoded by Unico), English characters are saved in the database, if the field type is varchar, it will only occupy one byte, and if the field type is nvarchar, it will occupy two bytes.
Under normal circumstances, we can also store Chinese characters with varchar, but if the operating system is an English operating system and the support for Chinese fonts is not comprehensive, there will be garbled codes when storing Chinese characters as varchar in SQL. And under normal circumstances, the Chinese environment is mainly supported, so if you use varchar to store data, it will not be found in the development phase, in most cases, in deployment.
Of course, using nvarchar to store English characters doubles the storage space, but when the storage cost is already very low, giving priority to compatibility will bring you more benefits.
So try to use nvarchar to store data in design, and use varchar to store data only when you make sure that the field does not save Chinese.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.