Data type--mysql

Source: Internet
Author: User
Tags set set

1. Numbers:
    Integral type: tinyinit  int  bigint

The Tinyinit int bigint, respectively, refers to the different number widths, from the smallest to the largest
There are also int (5) in parentheses after the number, for the deposit is not any difference, and for the take, if the number of the deposit is not 5 wide,
Then the front will be added 0 to gather 5, such as: Enter 123, the output is 00123. But it's not usually shown.
You can show it by adding Zerofill.
CREATE table n3 (x int (3) zerofill)
As long as the number is less than three digits, it is preceded by 0.

Decimal: float: Less precise in the case of a shorter number of bits: inaccurate 0.000001230123123123 in the case of a longer bit: 0.000001230000 Decimal: (If using decimal, the recommended decimal) the precise internal principle is stored as a string
where decimal, and the other forms of decimals are in decimal (10,5), represent a total of 10 digits, followed by a decimal point can only be followed by 5 bits, which exceeds the rounding operation.
And the front can not be more than 5 digits, more than 5 digits on the error. If the decimal point is not sufficient, then 0 is added to the back to gather 5 bits.

2. Characters:
CHAR (10)
Fast access, high space consumption, simple and rough.
Char (Ten) ==>char (name) ==>char (name000000), when the number of digits is not enough, 0 complement.
Save also save 10 bit, take also take 10 bit, so speed fast.
varchar (10)
Slow access speed, small space, save space. Precision

varchar before passing to other people's data, in order to accurately take, will be added in front of a header, late fetch, will first take the header, after the operation, the corresponding amount of information, like the header of the socket.

Char_length look at the length of the character, length to see how long the byte is, that is, the bytes type.

Select Char_length (x) from name:

Bit type:

That is, the bytes type, look at the byte type length, use the function, Bin ()

Select Bin (x) from N3.

Select Hex (x) from N3.

3rd period Type

DATE time DATETIME TIMESTAMP Year

Role: Store user registration time, article release time, employee entry time, birth time, expiration time, etc.

Date of birth: show-year-month-day- time-Division datetime: Year: Date date format: INSERT into N3 values (date of birth, year, time, month date); If you want to show the current time then: You can use Now ()
If you want to add it manually: If you have a special symbol (2017-09-10) then add the "(quotation mark) format: INSERT into N3 values (birth time Now (), year now (), Time Now (), month and day (s)); that is, show the current time.

5: Enum type and collection type

Enumeration--enum:

enum:create table N1 (name enum ('sdf','fd')); INSERT INTO N1  values ('sdf'); enum type refers to: Select one of the elements in a list, As your own value. If you want to change the enumeration type, you should delete the value you created with the enumeration type. 1) truncate N1           Delete all enumerations created by the value 2) alter ...           Change Enum type

Collection-set Type

Set set: A set refers to a tuple that takes one or more values. CREATE TABLE n1 (Name set (' A','123','456') insert into N1 values ('12,123'); If you want to change the set type, just like the enum type, delete everything that has the contents of the collection element to change1) truncate N1;2) Alter,...... Note: Inside the collection, if you want to take the 2 elements inside, then you can't write ('S','b'), to be written ('s,b'that is, a colon consists of 2 elements, and the elements inside are separated by commas.

6:constraint host_port Unique (host,port) overall meaning: constraint host_port is unique, that is, the contents of the parentheses in the back can be
One of the same, but not 2 equals.
CREATE TABLE Department3 (ID int,name varchar), comment varchar, constraint pk_name Primary key (ID); Here the pk_name is just a decoration, no use, the last word means to set the ID as the primary key,

The use of 7:auto_increment

CREATE TABLE t1 (ID int primary key auto_increment, name char (2), age int) auto_increment=3; indicates that the default initial self-increment value is 3, If you do not specify an ID value, the default is incremented from 3. Ps: This is set from the beginning 2) CREATE TABLE t1 (ID int primary key auto_increment, name char (2), age int) If the program has started running, Now if you want to modify the value of self-increment, change ALTER TABLE N1 auto_increment =3 in the back,starting fromnow 3.

8;foreign key: The element inside the associated table must be the primary key, which is the only one.

References T1 (ID) is referenced by the ID of the T1 table
On DELETE Cascade to concatenate the delete
On UPDATE cascade the update in series.










Data type--mysql

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.