MySQL Database update detailed description (1/4)

Source: Internet
Author: User
Tags ming mysql tutorial

First, insert and replace

The INSERT and replace statements have the ability to insert new data into a table. The syntax for these two statements is similar. The main difference between them is how to handle duplicate data.

1. General usage of Inserts

The INSERT statement in the MySQL tutorial is not the same as the standard insert, and in a standard SQL statement, there is only one form of INSERT statement that inserts one record at a time.

INSERT INTO tablename (column name ...) VALUES (column value);

And there's another form in MySQL.

INSERT INTO tablename set column_name1 = value1, column_name2 = value2, ...;

The first method separates the column names from the column values, and when used, the column names must be the same as the number of column values. As the following statement inserts a record into the users table:

Insert into the users (ID, name, age) VALUES (123, ' Yao ', 25);

The second method allows column names and column values to appear and be used in pairs, such as the following statement, which produces a medium-like effect.

INSERT INTO users set id = 123, name = ' Yao Ming ', age = 25;

If you use the Set method, you must assign at least one column. If a field uses a saved value (such as Default or self-increment), these fields can be omitted from either of these methods. The above two statements can be written in the following form, such as using the self-increment on the ID field:

Insert into the 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 the new record using the default values for each column in the table.

Home 1 2 3 4 last page
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.