/ *这是我用来合并的代码,但出现错误,无法更新
错误: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

最佳答案

您可能会使用以下代码:

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)

10-05 21:28