An introduction
The basic principle of replace into is introduced in the previous article. This chapter provides an example of the potential data quality risk associated with the replace into, and when a table involving a replace into operation contains a self-added primary key, the primary switch causes inconsistencies in data coverage, and so on.
Two cases analysis
Operating on the main library
Root@test 12:36:51>show CREATE table T1 \g
1. Row ***************************
Table:t1
Create table:create Table ' T1 ' (
' id ' int (one) not NULL auto_increment,
' Name ' varchar DEFAULT NULL,
PRIMARY KEY (' id '),
UNIQUE KEY ' name ' (' name ')
) Engine=innodb DEFAULT Charset=utf8
1 row in Set (0.00 sec)
Root@test 12:37:41>insert into T1 (name) VALUES (' a ') check the T1 table structure on the primary repository at this time, Auto_increment is 2.
Root@test 12:37:51>show CREATE table T1 \g
1. Row ***************************
Table:t1
Create table:create Table ' T1 ' (
' id ' int (one) not NULL auto_increment,
' Name ' varchar DEFAULT NULL,
PRIMARY KEY (' id '),
UNIQUE KEY ' name ' (' name ')
) Engine=innodb auto_increment=2 DEFAULT Charset=utf8
1 row in Set (0.00 sec) for the replace into operation on the main library
Root@test 12:37:58>replace into T1 (name) VALUES (' a ');
Root@test 12:38:40>replace into T1 (name) VALUES (' a ');
Root@test 12:38:49>select * from T1;
+----+------+
| ID | name |
+----+------+
| 3 | A |
+----+------+
1 row in Set (0.00 sec) Check the T1 table structure in the primary repository at this point, notice auto_increment=4
Root@test 12:38:51>show CREATE table T1 \\g
1. Row ***************************
Table:t1
Create table:create Table ' T1 ' (
' id ' int (one) not NULL auto_increment,
' Name ' varchar DEFAULT NULL,
PRIMARY KEY (' id '),
UNIQUE KEY ' name ' (' name ')
) Engine=innodb auto_increment=4 DEFAULT Charset=utf8
1 row in Set (0.00 sec) T1 table structure from the library, auto_increment=2
Root@test 12:39:35>show CREATE table T1 \g
1. Row ***************************
Table:t1
Create table:create Table ' T1 ' (
' id ' int (one) not NULL auto_increment,
' Name ' varchar DEFAULT NULL,
PRIMARY KEY (' id '),
UNIQUE KEY ' name ' (' name ')
) Engine=innodb auto_increment=2 DEFAULT Charset=utf8
1 row in Set (0.00 sec)
Root@test 12:39:43>select * from T1;
+----+------+
| ID | name |
+----+------+
| 3 | A |
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