I. insert and replace
Both insert and replace statements insert new data into the table. The syntax of these two statements is similar. The main difference between them is how to process repeated data.
1. General insert usage
The insert statement in the mysql tutorial is not the same as the standard insert statement. In the standard SQL statement, the insert statement that inserts a record at a time has only one form.
Insert into tablename (column name ...) Values (column value );
There is another form in mysql.
Insert into tablename set column_name1 = value1, column_name2 = value2 ,...;
The first method separates the column name from the column value. during use, the column name must be consistent with the number of column values. The following statement inserts a record into the users table:
Insert into users (id, name, age) values (123, 'Yao Ming ', 25 );
The second method allows the column names and column values to appear and use in pairs. The following statement will produce the same effect.
Insert into users set id = 123, name = 'Yao Ming ', age = 25;
If the set method is used, a value must be assigned to at least one column. If a field uses a missing value (such as default value or auto-increment value), you can omit these fields in either of the two methods. If auto-increment is used in the id field, the preceding two statements can be written as follows:
Insert into users (name, age) values ('Yao ming', 25 );
Insert into uses set name = 'Yao Ming ', age = 25;
Mysql has also made some changes in values. If nothing is written in values, mysql inserts a new record using the default value of each column in the table. 1 2 3 4