|
#
1
How to prevent duplicate info when we do mysql insert? |
 |
|
|
hans |
|
|
|
| Online |
no |
| State |
|
| Grouping |
Member |
| Class |
class4 |
| Score |
230 |
| Wealth |
160 |
| Posts |
161 |
| Login |
21:29:50 |
|
|
|
i have experience with batch products upload for an online shop web site. All info are stored in mysql query file called products.sql before upload, so prevent duplicate is important. I simple use the following syntax:
insert into table(title,qty) values("USB flash abb",'100') on duplicate key update qty='100';
The title column is unique. If it does not exist, perform insert ,otherwise it exists, perform update.
Other ways:
REPLACE INTO table set title='title',qty='100'
INSERT IGNORE INTO table set title='title',qty='100'
The second one: if there are errors in products.sql, the query will be stopped Hits: 813, Date: 2010-03-30 00:46:24
|
|
|
|