Example of mysqlinsertinto usage

Source: Internet
Author: User
In mysql, you can use insertinto to insert records into the database. you can insert one or more records according to different statements. This article introduces how to use insertinto in mysql. First, let's take a look at the insert into syntax in mysql:

INSERT INTO table_name VALUES (value1, value2,....)

You can also specify the columns in which you want to insert data:

INSERT INTO table_name (column1, column2,...)VALUES (value1, value2,....)


Note: SQL statements are case-insensitive. Insert into is the same as insert.

Example 1: multiple groups of values can be inserted in an insert statement at a time. each group of values is enclosed by a pair of parentheses and separated by commas, as shown below:

insert into `news`(title,body,time) values('title 1','body 1',now()),('title 2','body 2',now());

Example 2: The Insert Select statement inserts the query result into a new table. as the name suggests, it consists of an insert statement and a select statement.

insert into news_one(id,title,body,time) select id,title,body,time from news_two;

When using php, note that the two tables have the same structure and different column names.

The code for the "insert. php" page is as follows:


  

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.