Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Supressing Unique Index Violation Errors 1

Status
Not open for further replies.

cLFlaVA

Programmer
Jun 14, 2004
6,450
US
Hi all.

I have the following query in a php/mysql application:

Code:
insert tags ( `tag_name`, `tag_entry_id` )
values ( 'cory', 3 ),
       ( 'bob', 3 ),
       ( 'tim', 3 )

where the table has a unique index on tag_name and tag_entry_id (combined). i was hoping this would insert three records if none of them already exist, which it does. i was also hoping that if a "bob" record already exists for entry 3, that cory and tim would still be added.

it appears only cory is added, then the error (duplicate) occurs, then it craps out. do you know of any way to accomplish this? i don't want to test for existence, delete, then insert.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
You could use INSERT IGNORE, which will drop any new records which would cause an duplicate-key violation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top