views:

57

answers:

2

What happens in mysql multiple records insert during an error. I have a table:

id  | value
2   | 100
UNIQUE(id)

Now i try to execute the query:

INSERT INTO table(id, value) VALUES (1,10),(2,20),(3,30)

I will get a duplicate-key error for the (2,20) BUT... Will the (1,10) get into the database? Will the (3,30) get into the database?

+2  A: 

in your case the whole query will fail and you won't have any of the rows you've tried to insert into your table

PierrOz
+2  A: 

as PierrOz pointed out in your case nothing will be inserted,

but you might want to look into the 'on duplicate key update' clause of the insert statement:

lexu
yep good point about the "on duplicate key" :)
PierrOz