Santy
Santy

Reputation: 85

Insert multiple rows into a table and capture any errors during insert

I am trying to insert multiple rows into a table and if one of the rows are violating any rule I want to capture that row alone and rest of them should be inserted.

Is there any way of doing this in SQL server by using queries and not SSIS?

Upvotes: 1

Views: 180

Answers (2)

japesu
japesu

Reputation: 134

Where do these rows you are inserting come from? You could try a cursor for example where you can check the insert data before inserting and insert it to a fault table if the validation fails.

Upvotes: 0

Mikael Eriksson
Mikael Eriksson

Reputation: 138960

No, that is not possible. If one of the rows you try to insert fails the entire insert will fail.
You can try to figure out beforehand what rows will fail and not include those rows in the insert.

Upvotes: 1

Related Questions