我有 2 个表,其中一个是 Stage 表,其模式与 main 完全一致,我想将数据从 stage 表更新到 main 表,并将 ID 列作为 refrential 键。我曾尝试在 SQL 中使用 Merge,但遇到了问题,因为只有很少的值需要更新,并且需要将数千个新值插入到主表中。例如:
MERGE TABLE tblMain AS main
USING (SELECT ID,NAME,EMAIL_ID FROM tblStage) as stage
ON main.ID=stage.ID
WHEN MATCHED THEN UPDATE SET
main.ID=stage.ID,
main.NAME=stage.NAME,
main.EMAIL_ID=stage.EMAIL_ID
WHEN NOT MATCHED THEN INSERT VALUES
(
----I am stucked here what to write as there are thousands of values:(
)