MySQL Table update operation

Source: Internet
Author: User
Tags bulk insert

1. insert a new recordinto the table using the INSERT statement, with the following syntax: INSERT into table name [( field List )] values(Value list).

2. Update the operation and character set using the SET statement, for example setcharacter_set_client =latin1\gbk\utf8;

3. Delete the table record using the DELETE statement, for example delete from table name where conditional expression;

4,   Use the insert statement to bulk insert multiple records into a table at once, with the statement: insert  into ), (value list 2 n

5,   Use the insert...select insert result set, Syntax Insertinto [( 1)] Select (field name 2 source table where conditional expression; For example, Create Table statement responsible for quickly creating a new Student table, And the structure of the table and the student Student table structure is the same. insert statement will students Student All records in table are inserted new_student select statement responsible for querying new_student all records of the table, execution results are as follows:

Create tablene_student like student;

Insert intonew_student select * from student;

Select * Fromnew student;

6. insert new record with replace, there are three kinds of statement format:

syntax format 1:replace into table name [(Field list name)]values(Value list)

syntax Format 2:replace [into] target table name [( field List 1)]

Select(Field List name 2)from source table where conditional expression

Syntax format 1, Syntax format 2 is similar to the syntax format of an INSERT statement.

syntax Format 3:

Replace [into] table name

Set field 1= value 1, field 2= value 2

statement Format 3 is similar to the syntax format of the UPDATE statement.

The Replace statement is basically the same as the INSERT statement, except that when you use the Replace statement to insert a new record into a table, the new record's primary key value or uniqueness constraint has the same field value as the old record. The record is deleted first (note: The old record cannot be violated by the foreign KEY constraint), and then the new record is inserted. The biggest benefit of using replace is that you can combine the delete and insert to form an atomic operation so that the delete operation does not have to be associated with the insert The operation is placed in a transaction.


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.