6-12 varchar and char enum types enum Set set

Source: Internet
Author: User

1 character types Char and varchar

#官网: https://Dev.mysql.com/Doc/Refman/5.7/En/Char. html# Note: The parameters in char and varchar brackets refer to the length of the character #char type: fixed length, simple rough, wasted space, fast access speed range of characters:0-255(a Chinese is a character that is a UTF8 encoded 3 bytes) Store: When a value of type char is stored, a space is padded to the right to satisfy the length, for example: Specify a length of 10, save>10 characters error, save<10 characters are padded with spaces until 10 characters are stored for retrieval: When retrieving or saying a query, the results are automatically deleted trailing blanks unless we open pad_char_to_full_length SQL mode (set SQL mode:SETSql_mode= 'Pad_char_to_full_length'; Query the default mode for SQL:Select @ @sql_mode;) #varchar类型: variable length, precision, space saving, slow access speed range of characters:0-65535(If greater than 21845 will prompt for other types.) MySQL row maximum limit is 65535 bytes, character encoding is UTF-8: https://Dev.mysql.com/Doc/Refman/5.7/En/column-Count-limit.html) Storage: The varchar type stores the actual contents of the data, does not fill with spaces, if'AB', the trailing spaces will be saved. Emphasize: varchar type will add 1 before real data-A prefix of 2Bytes that is used to represent the number of bytes bytes of real data (1-2Bytes Maximum represents 65,535 digits, exactly as MySQL has a maximum byte limit on row, which is sufficient to use if the actual data<255bytes requires a 1Bytes prefix (1Bytes=8bit 2**8 The maximum representation of the number is 255) if the real data>255bytes requires a 2Bytes prefix (2Bytes=16bit 2**16 The maximum representation of the number is 65535) search: The trailing space will be saved, in the search or query, will also display the contents of the text, including spaces

You can use these two functions to verify:

Length (): View number of bytes char_length (): View characters

Summarize

#常用字符串系列: char vs. varchar NOTE: Although varchar is more flexible to use, the char data type is processed faster and sometimes exceeds the varchar processing speed from the overall system performance perspective%. Therefore, the user should design the database in a comprehensive consideration of various factors in order to achieve the best balance # Other string series (efficiency:Char>varchar>text) Text Series TinytextTEXTmediumtext Longtextblob Series Tinyblob BLOB mediumblob longblob binary seriesBINARY VARBINARYtext: The text data type is used to hold large, variable-length strings that can be set up to 65535 (2** -?1) characters. Mediumtext:aTEXT column  withA maximum length of  -,777,215(2** -?1) characters.longtext:aTEXT column  withA maximum length of 4,294,967,295 or4GB (2** +?1) characters.

2, enumeration types and collections

The value of a field can be selected only in a given range, such as a radio box, a multi-marquee

The enum radio can only select a value within a given range, such as gender sex sex male male/female female

Set multiple selection You can select one or more values within a given range (hobby 1, hobby 2, hobby 3 ...) )

Mysql> Create TableConsumer ( -Idint,     -Namevarchar( -),     -Sex enum ('male','female',' Other'),     -  LevelEnum'Vip1','VIP2','VIP3','VIP4'), #在指定范围内, choose one more -FavSet('Play','Music','Read','study') #在指定范围内, Multi-Select - ); Query OK,0Rows Affected (0.03sec) MySQL> Insert  intoConsumerValues     -(1,'Zhao Yun','male','VIP2','Read,study'),     -(2,'Zhao Yun 2',' Other','VIP4','Play'); Query OK,2Rows Affected (0.00sec) Records:2Duplicates:0Warnings:0MySQL> Select *  fromconsumer;+------+---------+-------+-------+------------+|Id|Name|Sex|  Level |Fav|+------+---------+-------+-------+------------+|    1 |Zhao Yun|Male|Vip2| Read, study||    2 |Zhao Yun 2|Other|Vip4|Play|+------+---------+-------+-------+------------+Rowsinch Set(0.00Sec

6-12 varchar and char enum types enum Set set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.