Correct usage of MySQL auto-incrementing primary key and TEXT Data Types

Source: Internet
Author: User

This article mainly describes the correct use of the MySQL auto-incrementing primary key and TEXT data types. Sometimes we will use the MySQL database and also use the auto-incrementing primary key and TEXT data types. To prevent forgetting, first record the TEXT data type length:

 
 
  1. TINYTEXT: 256 bytes   
  2. TEXT: 65,535 bytes => ~64kb   
  3. MEDIUMTEXT: 16,777,215 bytes => ~16MB   
  4. BIGTEXT: 4,294,967,295 bytes => ~4GB  

For the table I want to create, the primary key uses auto-incrementing numbers. If a data column uses the TEXT data type to store TEXT, you can write the following SQL statement:

 
 
  1. CREATE TABLE Corpus  
  2. (  
  3. id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,  
  4. data TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,  
  5. PRIMARY KEY (id) 

) Explain two concepts first:

Character Set is a set of symbols and encoding. Character set x indicates that the character set is SET to X.

A collation is a set of rules used to compare characters in a character set. There is a naming convention for proofreading rules: they start with their relevant Character Set names, usually include a language name, and are case-insensitive to _ ci), _ cs case-sensitive), or _ bin binary) end.

COLLATE utf8_general_ci indicates that the case-insensitive collation of utf8_general seems to be the default collation of the utf8 character set. Use "show collation like 'utf8% ';" to view details ). The table name is Corpus. The primary key is id. The MEDIUMINT data type can be used to indicate the approximate values of integers ranging from 1 to 999999, which is not accurate and easy to remember ~); UNSIGNED indicates the UNSIGNED type; AUTO_INCREMENT indicates the auto increment. The data column uses the TEXT data type and sets the character set of the column to utf8. The proofreading rule is utf8_general and case insensitive.


 

The above content describes the use of the MySQL auto-incrementing primary key and TEXT data types. I hope it will help you in this regard.

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.