aviv
aviv

Reputation: 2809

mysql multiple insert - what happens on error?

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?

Upvotes: 2

Views: 3230

Answers (3)

Muhammad Sayed
Muhammad Sayed

Reputation: 21

I thnik the answers are out-dated, you could use INSERT IGNORE statement

Upvotes: 1

lexu
lexu

Reputation: 8849

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:

Upvotes: 2

pierroz
pierroz

Reputation: 7880

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

Upvotes: 2

Related Questions