Welcome to the Linux community forum and interact with 2 million technical staff. # The result can only be seen as that all data in replace is strings. (In my opinion only) # updatemytablesetnamereplace (name, Wang erxiao, Wang Tiezhu); # This method cannot be passed # updatemytablesetcountreplace (cou
Welcome to the Linux community forum and interact with 2 million technical staff> enter # For such a result, it can only be seen that all data in replace is strings. (In my opinion only) # update mytable set name = replace (name, Wang erxiao, Wang Tiezhu); # This method cannot be used # update mytable set count = replace (cou
Welcome to the Linux community forum and interact with 2 million technicians>
# For such a result, it can only be seen that all data in replace is strings. (Personal opinion only)
# Update mytable set name = replace (name, Wang erxiao, Wang Tiezhu); # This method cannot be used
# Update mytable set count = replace (count, '20160301', '20160301 ');
Mysql> update mytable set count = replace (count, '20140901', '20160901 ');
Query OK, 3 rows affected (0.00 sec) # It is indeed the expected result
Rows matched: 11 Changed: 3 Warnings: 0
# Therefore, data in replace is only a string
Mysql> update mytable set count = replace (count, '20140901', '20160901 ');
Query OK, 6 rows affected (0.00 sec) # prove the result again
Rows matched: 11 Changed: 6 Warnings: 0
# In summary, replace can be used to replace multiple data in a field or different fields.
# In mysql, replace can act as insert within a certain range, and the syntax is similar
# Replace into mytable (name, count) values ('raffles ', '70'), ('Rio Tinto', '123 ');
Mysql> replace into mytable (name, count) values ('raffles ', '70'), ('Rio Tinto', '123 ');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
# What if the database has similar data?
Replace into mytable (name, count) values ('laifu', '70 ');
Mysql> replace into mytable (name, count) values ('laifu', '70 ');
Query OK, 1 row affected (0.00 sec)
# Here we will look at the index of the table. It seems that the index is the default ID.
Mysql> show index from mytable;
+ --------- + ------------ + ---------- + -------------- + ------------- + ----------- + ----
--------- + ---------- + -------- + ------ + ------------ + --------- +
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Car
Dinality | Sub_part | Packed | Null | Index_type | Comment |
+ --------- + ------------ + ---------- + -------------- + ------------- + ----------- + ----
--------- + ---------- + -------- + ------ + ------------ + --------- +
| Mytable | 0 | PRIMARY | 1 | id | A |
14 | NULL | BTREE |
+ --------- + ------------ + ---------- + -------------- + ------------- + ----------- + ----
--------- + ---------- + -------- + ------ + ------------ + --------- +
1 row in set (0.00 sec)
# According to the document, if there is only one index, replace is equivalent to insert.
# Remember that I have created two tables. Now we switch to the mytab table with less data for Operation Demonstration:
Mysql> show tables;
+ ---------------- +
| Tables_in_mydb |
+ ---------------- +
| Mytab |
| Mytable |
+ ---------------- +
2 rows in set (0.00 sec)
# The default index is id.
Mysql> show index from mytab;
+ ------- + ------------ + ---------- + -------------- + ------------- + ----------- + ------
------- + ---------- + -------- + ------ + ------------ + --------- +
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardi
Nality | Sub_part | Packed | Null | Index_type | Comment |
+ ------- + ------------ + ---------- + -------------- + ------------- + ----------- + ------
------- + ---------- + -------- + ------ + ------------ + --------- +
| Mytab | 0 | PRIMARY | 1 | id | A |
3 | NULL | BTREE |
+ ------- + ------------ + ---------- + -------------- + ------------- + ----------- + ------
------- + ---------- + -------- + ------ + ------------ + --------- +
1 row in set (0.00 sec)
# Now I need to add an index to it (I am in trouble here. It seems that I am not very familiar with index building. I am ashamed of myself ).
# An error occurred while trying to create multiple indexes. Write it here for the moment...
Writing this is not about not going to work, but about the schedule of the company's specific tasks for next week.
[1] [2]