Differences between char, varchar, text, nchar, nvarchar, and ntext
1. Char. It is very convenient for Char to store fixed-length data, and the indexing efficiency of char fields is high. For example, if char (10) is defined, no matter whether the data you store reaches 10 bytes, it takes up 10 bytes of space. If not, it is automatically filled with spaces.
2. varchar. Variable-length data is stored, but the storage efficiency is not as high as char. If the possible value of a field is not fixed, we only know that it cannot exceed 10 characters. It is the most cost-effective to define it as varchar (10.The actual length of the varchar type is the actual length of its value plus 1. Why "+ 1? This byte is used to save the actual length.From the perspective of space, it is appropriate to use varchar; from the perspective of efficiency, char is suitable, and the key is to find a trade-off point based on the actual situation.
3. Text. Text stores variable-length non-Unicode data. The maximum length is 2 ^ 31-1 (2,147,483,647) characters.
4. nchar, nvarchar, and ntext. The three names are named N more than the first three ". It indicates that characters of the Unicode data type are stored. We know that only one byte is required for English characters, but there are many Chinese characters and two bytes are required for storage. It is easy to cause confusion when both English and Chinese characters exist, unicode Character Set is generated to solve the incompatibility problem of character sets. All its characters are expressed in two bytes, that is, English characters are also expressed in two bytes. The length of nchar and 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. Char and varchar can store up to 8000 English and 4000 Chinese characters. It can be seen that when using nchar and nvarchar data types, you do not have to worry about whether the entered characters are English or Chinese characters, which is more convenient, but there is some loss in the amount of stored English hours.
Therefore, in general, if it contains Chinese characters, use nchar/nvarchar. If it contains pure English characters and numbers, use Char/varchar.
The biggest feature of SQLite is that its data type is typelessness ). This means that data of any type can be saved to any column of any table to be saved, regardless of the Data Type declared by this column. Although the data type of each field needs to be declared when the table structure is generated, SQLite does not perform any checks. Developers rely on their own programs to control the types of input and read data. An exception is that when the primary key is an integer value, an exception occurs if a non-integer value is to be inserted.
Although SQLite allows data types to be ignored, we recommend that you specify the data type in the create table statement, because the data type facilitates program readability. In addition, although data types are not differentiated during data insertion or reading, different data types are different during comparison.
From: http://hi.baidu.com/lifushuilove/blog/item/3d8d20721c744c158601b068.html