Types of MySQL data and constraints on fields "Focus"

Source: Internet
Author: User

1. Make sure that the MySQL field "includes the library name, the table name" is correct, necessary to use the anti-quote


2. Proofing Set
Refers to the relationship between characters "character handling of field values"
Collation set dependent on character set
Proofing sets: Under a character set, the sort relationships of these characters are called proofing sets
"Some sort of field"

In phpMyAdmin to set the library encoding, the use of the end of the CI encoding is used by the proofing set "default is used, but in fact, the proofing set is basically not used"

_bin: Direct comparison of binary coding levels
_ci: Ignoring case
_cs: Case not ignored
"Http://www.jb51.net/article/30865.htm"

3. Integral Type Introduction
SQL itself is a strongly typed language
tinyint
smallint
Mediumint
int occupies 4 bytes
bigint

The number of bytes occupied is absolutely their range.
and control of negative numbers "control of symbols"
Int (Ten) unsign "0 padding, if not to this number of digits, the front fill 0" "and beyond this number, then directly display"
MySQL does not have a Boolean type, but it has the Boolean keyword "tinyint type"

4. Floating-point type
Single-precision: four bytes of storage space, can represent a significant number of 7-bit "float"
Double precision: Eight bytes of storage space, can represent the number of significant digits of 16-bit "double"

Because of the accuracy of the floating-point number itself, we do not use floating-point numbers for accurate representation of the data "or to determine equality"

The fixed-point number "is like a string to store" "The decimal point is OK"


5. String type
Char
varchar "The length here refers to the number of characters"
Text "SQL Server intercepts the string, and if it takes less data, the conversion type is required to fetch the data."

Note
(1) The maximum length of a record in MySQL is 65535 bytes "All fields in the row are added together and this byte range" "needs to take into account the number of bytes encoded to determine the length." Because the length of the record is determined by the number of characters "
But the text type of data is not counted into the byte limit of a record

6. Enumerations and collections
The enum single Selection "int (1) can also be expressed as"
Collection "Set: Check"

These two types are rarely used


7. Date and Time type
The type of time used to record the relevant data "this piece of content is working properly"

"Managed as an integral type, but presented as a string"


8. Column Constraints column properties, field constraints
Settings to limit the related conditions of a field "default condition"
(1) NULL attribute constraint "This field indicates that the data is not stored, not that the field must be null." The optional field is the limit "" Not null means the field cannot be empty "
(2) Default value constraint "A value needs to specify a default value in cases where no value is specified to implement the default value"
However, NULL and default cannot be defined together, but the basic settings of the field are implemented by Null,not Null,default
"But the constraint properties of default and Null are not consistent, i.e. the value of default is not itself null"
(3) Current_timestamp Such a limit field "represents the current timestamp"
Focus
(4) The primary key index and the unique index constraint "guarantee that the field at that location in each row of records is subject to this restriction: This constraint allows for better features"
"Here we can infer that the function of the index is to constrain the field (the equivalent of creating a new file to mark the field) to find the data for that field."
"Primary keys and unique indexes can consist of multiple fields, called composite primary keys. But this usage is less "
"How to manage primary keys and unique indexes: Modify, delete, add (ALTER TABLE name" Add Primary_key) "
The self-growth auto_increment is used to describe the primary key. A more layer of constraint equivalent to the PRIMARY KEY constraint "

"Note that the use of unsigned is not a column constraint, but a part of a type. Unsigned is understood as a data type designation can "

Types of MySQL data and constraints on fields "Focus"

Related Article

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.