SQL INSERT into syntax and instance

Source: Internet
Author: User
Tags mysql tutorial

INSERT INTO statement

The INSERT INTO statement is used to insert a new row into the table.

Grammar

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

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

INSERT INTO table_name (column 1, column 2,...) VALUES (value 1, value 2,....)
Now look at the insert instance
 
 

Insert into Tbl_name (col1,col2) values ( );

This is to save a record, if I have to operate more than one

The code is as follows Copy Code
$a = 1;
$b = 1;
while (5 == $a)
{
$sql = "INSERT into Tbl_name (col1,col2) VALUES ($a,$b)";
MySQL Tutorial _query($sql);
$a++;
$b++;
}

This method is very efficient, if it is 1 trillion times, it will be time-consuming. Here's another way to save multiple records using INSERT INTO

The code is as follows Copy Code
Insert into ' usertable ' (' user_id ', ' user_name ') Values
(1, ' DSF ') ,
(2, ' fgy ') ,
(3, ' Faad ');

Improve the While

The code is as follows Copy Code
$a = 1 ;
while ( 5 == $a )
{
if ( 1 == $a )
$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.