SQLite - UPSERT *not* INSERT or REPLACE

后端 未结 18 2596
猫巷女王i
猫巷女王i 2020-11-21 23:53

http://en.wikipedia.org/wiki/Upsert

Insert Update stored proc on SQL Server

Is there some clever way to do this in SQLite that I have not thought of?

18条回答
  •  别跟我提以往
    2020-11-22 00:31

    SELECT COUNT(*) FROM table1 WHERE id = 1;
    

    if COUNT(*) = 0

    INSERT INTO table1(col1, col2, cole) VALUES(var1,var2,var3);
    

    else if COUNT(*) > 0

    UPDATE table1 SET col1 = var4, col2 = var5, col3 = var6 WHERE id = 1;
    

提交回复
热议问题