R
R
Roman Rakzin2017-10-29 20:14:21
SQL
Roman Rakzin, 2017-10-29 20:14:21

Multiple SQL Insert does not work if one of the rows does not fall under the unique index condition.?

There is a unique index on several columns (Name, Datetime). I periodically make a request to another service and enter data into my table. I form a multiple Insert query, and first all the data is entered, and then when updating from the service, part of the data is the same and I enter the data into the table, but since the unique index blocks the entry, the entire query does not work.
I want to insert only those rows that are new. Those that have not changed, do not insert.
Example - I monitor the number of products :)) on the service

яблоки  29.10.2017 18:00:00 20(тонн)
    груши   29.10.2017 18:00:10 60(тонн)

In a minute
яблоки  29.10.2017 18:01:00 1000(тонн)  //ИЗМЕНИЛОСЬ
    груши   29.10.2017 18:00:10 60(тонн)    //не ИЗМЕНИЛОСЬ- тоже отправлять на вставку,но эта строка не отработает из за уникального индекса

then again I update and it is necessary to insert only those that were not there.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2017-10-29
@Rsa97

What dialect of SQL?
For MySQL - INSERT IGNORE or INSERT ... ON DUPLICATE KEY UPDATE

M
Maxim Y, 2017-10-30
@x_shader

If Oracle - MERGE
www.sql.ru/blogs/oracleandsql/1927

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question