The practical application of my work. When collecting data, it is not necessary to repeat it after collection. At the same time, multiple instances are required to operate simultaneously to ensure the continuity of data acquisition. So summed up, made the following small experiment. The core code is as follows:
Table structure: only 3 fields
Id,name,password
SQL code
CREATE TABLE ' TT ' (
' Id ' int (one) not null auto_increment,
' name ' varchar (255) DEFAULT null,
' password ' varcha R (255) default NULL,
PRIMARY KEY (' Id ')
) engine=innodb default Charset=utf8;
SQL statement
1) Recommended
SQL code
Insert ignore into TT (Name,password) VALUES (' PHL ', ' 123 ')
2 is not recommended, because select will lock the Select table when insert
SQL code
INSERT INTO TT (name,password) Select ' PHL ', ' 123 ' to dual where NOT EXISTS (SELECT * from TT where name= ' PHL ' and password = ' 123 ')
The meaning of this SQL statement is that if the inserted data name= ' PHL ', password= ' 123 ' does not exist, the insertion is performed;
Add:
Method 1, there is no filter. It is because there is no joint master building of name and password;