如何在DB2中以优化的方式更新多个查询

时间:2015-09-14 10:37:57

标签: c# db2

请找到以下代码 -

UPDATE TENDORS SET TENDORS_VALUE = 080 WHERE ID = 1245789633 AND TENDOR_DATE = 2012-01-02;   
UPDATE TENDORS SET TENDORS_VALUE = 080 WHERE ID = 1235853861 AND TENDOR_DATE = 2011-02-22;     
UPDATE TENDORS SET TENDORS_VALUE = 0A0 WHERE ID = 2565854283 AND TENDOR_DATE = 2013-11-19;    
UPDATE TENDORS SET TENDORS_VALUE = 0A0 WHERE ID = 0565853935 AND TENDOR_DATE = 2012-02-02;    
UPDATE TENDORS SET TENDORS_VALUE = 080 WHERE ID = 5565854148 AND TENDOR_DATE = 2013-07-02;    
UPDATE TENDORS SET TENDORS_VALUE = 480 WHERE ID = 4565850296 AND TENDOR_DATE = 2012-12-20;     
UPDATE TENDORS SET TENDORS_VALUE = 480 WHERE ID = 4565850507 AND TENDOR_DATE = 2012-10-12;     
UPDATE TENDORS SET TENDORS_VALUE = 480 WHERE ID = 4565850644 AND TENDOR_DATE = 2012-09-02;    
UPDATE TENDORS SET TENDORS_VALUE = 480 WHERE ID = 4565851488 AND TENDOR_DATE = 2012-08-02;    
UPDATE TENDORS SET TENDORS_VALUE = 080 WHERE ID = 4610849238 AND TENDOR_DATE = 2012-07-02;    
UPDATE TENDORS SET TENDORS_VALUE = 4A0 WHERE ID = 4610849238 AND TENDOR_DATE = 2012-06-02;    
UPDATE TENDORS SET TENDORS_VALUE = EB0 WHERE ID = 4610849238 AND TENDOR_DATE = 2012-05-02;    
UPDATE TENDORS SET TENDORS_VALUE = EA0 WHERE ID = 4610850154 AND TENDOR_DATE = 2012-04-02;     
UPDATE TENDORS SET TENDORS_VALUE = EA0 WHERE ID = 4610850154 AND TENDOR_DATE = 2012-03-02;    
UPDATE TENDORS SET TENDORS_VALUE = EA0 WHERE ID = 4610850154 AND TENDOR_DATE = 2012-12-02;     
UPDATE TENDORS SET TENDORS_VALUE = CA0 WHERE ID = 4610851768 AND TENDOR_DATE = 2012-08-02;     
UPDATE TENDORS SET TENDORS_VALUE = CA0 WHERE ID = 4610851768 AND TENDOR_DATE = 2012-07-02;    
UPDATE TENDORS SET TENDORS_VALUE = CA0 WHERE ID = 4610851768 AND TENDOR_DATE = 2012-06-02;    
UPDATE TENDORS SET TENDORS_VALUE = 8B0 WHERE ID = 4565853935 AND TENDOR_DATE = 2012-05-02;    
UPDATE TENDORS SET TENDORS_VALUE = 8B0 WHERE ID = 4565854146 AND TENDOR_DATE = 2009-04-02;     
UPDATE TENDORS SET TENDORS_VALUE = 8B0 WHERE ID = 4565854146 AND TENDOR_DATE = 2009-03-02;    
UPDATE TENDORS SET TENDORS_VALUE = 9B0 WHERE ID = 4565854283 AND TENDOR_DATE = 2010-02-02;    
UPDATE TENDORS SET TENDORS_VALUE = 9B0 WHERE ID = 4565854283 AND TENDOR_DATE = 2011-01-02;

最多1000个更新语句

当我们执行上面的查询(即执行1000更新查询)时,它花费了太多时间。我想提高性能。

哪种方法可以在代码和时间方面对其进行优化?任何类如DB2BulkCopy for Update?或任何内置类以便在DB2或SQL中进行更新?

1 个答案:

答案 0 :(得分:0)

怎么样

WITH A(A,B,C) AS (VALUES
     ('080','1245789633','2012-01-02')   
    ,('080','1235853861','2011-02-22')     
    ,('0A0','2565854283','2013-11-19')    
    ,('0A0','0565853935','2012-02-02')    
    ,('080','5565854148','2013-07-02')    
    ,('480','4565850296','2012-12-20')     
    ,('480','4565850507','2012-10-12')     
    ,('480','4565850644','2012-09-02')    
    ,('480','4565851488','2012-08-02')    
    ,('080','4610849238','2012-07-02')    
    ,('4A0','4610849238','2012-06-02')    
    ,('EB0','4610849238','2012-05-02')    
    ,('EA0','4610850154','2012-04-02')     
    ,('EA0','4610850154','2012-03-02')    
    ,('EA0','4610850154','2012-12-02')     
    ,('CA0','4610851768','2012-08-02')     
    ,('CA0','4610851768','2012-07-02')    
    ,('CA0','4610851768','2012-06-02')    
    ,('8B0','4565853935','2012-05-02')    
    ,('8B0','4565854146','2009-04-02')     
    ,('8B0','4565854146','2009-03-02')    
    ,('9B0','4565854283','2010-02-02')    
    ,('9B0','4565854283','2011-01-02')
    )
SELECT COUNT(*) FROM NEW TABLE (
    UPDATE TENDORS
    SET TENDORS_VALUE = (SELECT A FROM A WHERE ID = B AND TENDOR_DATE = C)
    WHERE EXISTS        (SELECT A FROM A WHERE ID = B AND TENDOR_DATE = C)
)