Danger of using 'IF EXISTS… UPDATE .. ELSE .. INSERT' and what is the alternative?

后端 未结 4 1205
既然无缘
既然无缘 2021-01-17 03:42

This question is related with Occasionally Getting SqlException: Timeout expired. Actually, I am using IF EXISTS... UPDATE .. ELSE .. INSERT heavily in my app.

4条回答
  •  感情败类
    2021-01-17 03:51

    Sample MERGE statement in this case would be:

    MERGE INTO Table1 t1
    USING (SELECT 'SomeValue' as Column_id FROM dual) t2 ON
    (t1.column_id = t2.column_id)
    WHEN MATCHED THEN
        UPDATE SET(...)
    WHEN NOT MATCHED THEN
        INSERT (t1.column_id)
        VALUES ('SomeValue');
    

提交回复
热议问题