Mysql method to add rows: 1. Use the "INSERT INTO table name column name 1,...column name n VALUES (value 1..., value n);" statement, the order of column names and values corresponds; 2 , use the "INSERT INTO table name SET column name 1 = value 1, column name 2 = value 2,...;" statement to insert a row of data.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
In mysql, adding a row is to insert a row of data into the database table. The following article introduces two methods to you.
Method 1. Use INSERT...VALUES
statement
The syntax format is:
INSERT INTO <表名> [ <列名1> [ , … <列名n>] ] VALUES (值1 [… , 值n ]);
The syntax description is as follows:
Table name
: Specify the name of the table to be operated on.
Column name
: Specify the column name into which data needs to be inserted. If data is inserted into all columns in the table, all column names can be omitted and INSERT<table name>VALUES(…) can be used directly. <li><p><code>VALUES
or VALUE clause
: This clause contains the list of data to be inserted. The order of data in the data list should correspond to the order of columns.
Method 2: Use the INSERT...SET statement
The syntax format is:
INSERT INTO <表名> SET <列名1> = <值1>, <列名2> = <值2>, …
This statement is used to directly enter the table Certain columns in specify corresponding column values, that is, the column name of the data to be inserted is specified in the SET clause, col_name is the specified column name, and the equal sign is followed by the specified data. For unspecified columns, the column value will be assigned as the default value for the column.
Example:
insert values: Advantages: Can be inserted in batches; Disadvantages: Single execution efficiency is low.
insert into table(col1,col2,col3) values('val1','val2','val3');
insert set: Advantages: High execution efficiency; Disadvantages: Only one piece of data can be inserted at a time.
insert into table set col1='val1',col2='val2',col3='val3';
[Related recommendations: mysql video tutorial]
The above is the detailed content of How to add rows in mysql. For more information, please follow other related articles on the PHP Chinese website!