SQL INSERT INTO syntax and example

Source: Internet
Author: User
Tags mysql tutorial

The tutorial in this article is a simple SQL insert into syntax and an example. Let's take a look at the SQL insert into syntax and then look at the example to illustrate the insert into instance.

The tutorial in this article is a simple SQL insert into syntax and an example. Let's take a look at the SQL insert into syntax and then look at the example to illustrate the insert into instance.

Insert into statement

The insert into statement is used to insert new rows into the table.

Syntax
Insert into table name values (value 1, value 2 ,....)

You can also specify the columns to insert data:

Insert into table_name (column 1, column 2,...) values (value 1, value 2 ,....)
Insert an instance

Insert into tbl_name (col1, col2) values (15,16 );

This is to save one record. What if I want to operate multiple records?

 

$ A = 1;
$ B = 1;
While (5 = $)
{
$ SQL = "insert into tbl_name (col1, col2) values ($ a, $ B )";
Mysql tutorial _ query ($ SQL );
$ A ++;
$ B ++;
}

 

This method is very efficient. If it is 1e+06 million times, it will take a lot of time. Next we will look at another method to save multiple records using insert.

 

Insert into 'usertable' ('user _ id', 'user _ name') values
(1, 'dsf '),
(2, 'fgy '),
(3, 'faad ');

 

Improve while

 

$ A = 1;
While (5 = $)
{
If (1 = $)
$ SQL = "insert into tbl_name (col1, col2) values ($ a, $ B )";
Else
$ SQL. = ", ($ a, $ B )";

$ A ++;
$ B ++;
}
Mysql_query ($ SQL );

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.