MySQL Add and delete changes to the "increase"

Source: Internet
Author: User

There are two basic syntax for inserting a record:

Insert Basic Syntax One
category Detailed Solution
Basic syntax Insert into table values (value 1, value 2, value n);
Example INSERT into user values (2, ' php Chinese web ', ' male ')
Example description Insert a value ID of 2 to the user table, name Li Wenkei, sex is male
Insert Basic Syntax Two
category Detailed Solution
Basic syntax Insert into table (field 1, Field 2, field N) VALUES (value 1, value 2, value n);
Example INSERT into User (Id,username,sex) values (213, ' Little Shenyang ', 1);
Example description Insert ID 213,username to user table for small Shenyang, sex is 1
Description

The difference between basic Syntax 1 and basic Syntax 2 is:

    1. The INSERT statement for Basic Syntax 1, the number of fields in the table that must be inserted in the number of values. One cannot be more, nor one can be less. If there is a default value, do not want to pass, you can write null.
    2. Basic Syntax 2, unless a required field must be written to a value. If you do not want to write with a default value, you can ignore the write. MySQL will automatically fill in the default values.
    3. In basic Syntax 2, values are ordered in the same order as the user (Id,username,sex) field.

Given that there is a table for the user table, we describe the fields, field descriptions, types and fields, and the required states, with the following table structure:

Field ID username Email Password Sex
Chinese description Number User name Mailbox Password Gender
Type description Int varchar (50) varchar (60) varchar (32) tinyint
Default Value Description Self-increment Must fill in Optional field, the default value is [email protected]n Optional fields Required Fields
According to Basic Grammar OneWrite the INSERT statement in the table:

INSERT into user values (null, ' PHP Chinese web ', ' [email protected] ', NULL, 1);

Attention

    1. You can not specify a field name, but the order after values should be the same as the table field.
    2. A field with a default value can not be written, or it is the default value.
    3. You can write null if there is a default value or if a nullable field does not want to pass in a specific value.
    4. The data format must be consistent with the data format specified by the table.
According to Basic Syntax TwoWrite the INSERT statement in the table:

INSERT into User (Username,sex) VALUES (' PHP Chinese web ', 1);

Attention

    1. Self-increment IDs can be used without passing in values, and the value of this field is automatically increased by 1 each time it is inserted.
    2. Fields that have default values and can be empty do not pass
    3. The Insertion Order of table user (Username,sex) is whichever
    4. Basic syntax two for more common usage
Basic syntax morphing: inserting multiple records at once

INSERT into User (username,password,sex)
Values (' Huang Xiaoming ', ' abcdef ', 1),
(' Angelababy ', ' Bcdeef ', 0),
(' Chenhe ', ' 123456 ', 1),
(' Wangbaoqiang ', ' 987654 ', 1);

MySQL Add and delete changes to the "increase"

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.