When multiple records are inserted in batches, one insertinto inserts multiple identical records.

Source: Internet
Author: User
When multiple records are inserted in batches, one insertinto inserts multiple identical records. when multiple insert records are inserted in batches, one insert into inserts multiple identical records from time to time. what is the situation.
How should we solve this problem?


Reply to discussion (solution)

Please post the code !!!
Whether or not to repeat each time when batch addition is performed. If yes, check the code.

For ($ I = 0; $ I <$ s; $ I ++ ){
$ Iaps = $ iap [$ I];
$ Daqs = $ daq [$ I];
$ Row = mysql_query ("select count (*) from 'dls' where 'iap '=' $ iaps '"); // check whether duplicate data exists.
$ Row = mysql_fetch_row ($ row );
If ($ row [0]) {continue ;}


Mysql_query ("insert into 'dls' ('iap ', 'dash', 'KT') value ('$ iaps', '$ daqs', 'KT ')");

}

Loop problems.
1. it is best to solve the loop.
2. create a UNIQUE index for a field to avoid repeated inserts.
2. use the insert into from dual where not exists statement to avoid repeated inserts.

Insert into [table name] SELECT '[value1]', '[value2]' FROM DUAL
Where not exists (
SELECT [column1] FROM [same table name]
WHERE [column1] = '[value1]'
AND [column2] = '[value2]' LIMIT 1
)

It is best to use transactions to ensure consistency.

$ Row = mysql_fetch_row ($ row );
Var_dump ($ row); print the result.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.