MARIADB:基于另一个表中的数据插入和更新表

时间:2018-08-02 10:53:22

标签: mysql mariadb mariasql

/ *这是我用来合并的代码,但出现错误并且无法更新 错误:SQL错误[1064] [42000]您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以获取righr语法,以在第1行的'Merge temp2 as t'附近使用 * /

BEGIN
MERGE temp2 as t
using temp1 as s ON (t.slno = s.slno)
-- Insert values when data no present
WHEN NOT MATCHED THEN INSERT VALUES
(s.slno,s.name,s.address);
-- Update when values present
WHEN MATCHED then UPDATE SET
t.slno = s.slno,
t.name = s.name,
t.address = s.address;
END

1 个答案:

答案 0 :(得分:0)

您可能会用到它:

INSERT INTO temp2 (slno, name, address) SELECT slno, name, address FROM temp1 
ON DUPLICATE KEY UPDATE 
slno = VALUES(slno), name = VALUES(name), address = VALUES(address)