Mysql database update description (1/4)

Source: Internet
Author: User
Tags mysql tutorial

I. insert and replace

Both insert and replace statements insert new data into the table. The syntax of these two statements is similar. The main difference between them is how to process repeated data.

1. General insert usage

The insert statement in the mysql tutorial is not the same as the standard insert statement. In the standard SQL statement, the insert statement that inserts a record at a time has only one form.

Insert into tablename (column name ...) Values (column value );

There is another form in mysql.

Insert into tablename set column_name1 = value1, column_name2 = value2 ,...;

The first method separates the column name from the column value. during use, the column name must be consistent with the number of column values. The following statement inserts a record into the users table:

Insert into users (id, name, age) values (123, 'Yao Ming ', 25 );

The second method allows the column names and column values to appear and use in pairs. The following statement will produce the same effect.

Insert into users set id = 123, name = 'Yao Ming ', age = 25;

If the set method is used, a value must be assigned to at least one column. If a field uses a missing value (such as default value or auto-increment value), you can omit these fields in either of the two methods. If auto-increment is used in the id field, the preceding two statements can be written as follows:

Insert into users (name, age) values ('Yao ming', 25 );

Insert into uses set name = 'Yao Ming ', age = 25;

Mysql has also made some changes in values. If nothing is written in values, mysql inserts a new record using the default value of each column in the table. 1 2 3 4

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.