I have the following tables:
DataValue
DateStamp ItemId Value
---------- ------ -----
2012-05-22 1 6541
2012-05-22 2 12321
2012-05-21 3 32
tmp_holding_DataValue
DateStamp ItemId Value
---------- ------ -----
2012-05-22 1 6541
2012-05-22 4 87
2012-05-21 5 234
DateStamp
and ItemId
are the primary key columns.
I'm doing an insert which runs periodically throughout the day (in a stored procedure):
insert into DataValue(DateStamp, ItemId, Value)
select DateStamp, ItemId, Value from tmp_holding_DataValue;
This moves data from the holding table (tmp_holding_DataValue
) across into the main data table (DataValue
). The holding table is then truncated.
The problem is that as in the example, the holding table could contain items which already exist in the main table. Since the key will not allow duplicate values the procedure will fail.
One option would be to put a where clause on the insert proc, but the main data table has 10 million+ rows, and this could take a long time.
Is there any other way to get the procedure to just skip-over/ignore the duplicates as it tries to insert?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…