MySQL Update UPDATE statement fine solution 1th/2 page _mysql

Source: Internet
Author: User
Tags ming mysql update

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
Insert statements in MySQL are not the same as standard inserts, and in standard SQL statements 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.
INSERT into Users () VALUES ();
If you write nothing after the table name, you assign a value to all the fields in the table. In this way, not only values are consistent with the number of columns, but the order cannot be reversed. INSERT into Users VALUES (123, ' Yao ', 25);
If you write the INSERT statement in the following form, MySQL will make an error.
INSERT into Users VALUES (' Yao Ming ', 25);

2. Insert multiple records using Insert

See this title maybe people will ask, this has nothing to say, call multiple INSERT statements can not be inserted multiple records it! But using this method increases the load on the server because every SQL Server performs the same analysis, optimization, and so on. Fortunately, MySQL offers another solution, which is to insert multiple records using an INSERT statement. This is not a standard SQL syntax, so it can only be used in MySQL.
INSERT into the users (name, age) VALUES (' Yao Ming ', 25), (' Bill Gates ', 50), (' Martians ', 600);

current 1/2 page   1 2 Next read the full text
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.