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 );