Mysql 在SQL Server 2008中替换为
我尝试进行迁移,但我对此查询有问题:Mysql 在SQL Server 2008中替换为,mysql,sql-server-2008,migration,Mysql,Sql Server 2008,Migration,我尝试进行迁移,但我对此查询有问题: $DB->query("replace into periodetojour(idperiode,idjour,heure) values('".addslashes($idperiode)."','2','".addslashes($mardi)."')"); 我发现在SQL Server 2008中不能使用REPLACE-INTO,我必须使用MERGE-INTO 我的问题是,我找不到任何使用合并到的查询,因此我可能没有很好
$DB->query("replace into periodetojour(idperiode,idjour,heure)
values('".addslashes($idperiode)."','2','".addslashes($mardi)."')");
我发现在SQL Server 2008中不能使用REPLACE-INTO
,我必须使用MERGE-INTO
我的问题是,我找不到任何使用合并到的查询,因此我可能没有很好地使用它。您知道如何使用MERGE-INTO进行更改吗?在SQLServer2008中是否有义务进行更改
谢谢您的回答。在您的情况下,声明如下所示:
$DB->query("MERGE INTO periodetojour dst
USING (
SELECT '".addslashes($idperiode)."' idperiode,
'2' idjour,
'".addslashes($mardi)."' heure
) src
ON src.idperiode = dst.idperiode
WHEN MATCHED THEN UPDATE SET
dst.idjour = src.idjour,
dst.heure = src.heure
WHEN NOT MATCHED THEN INSERT (idperiode, idjour, heure)
VALUES(src.idperiode, src.idjour, src.heure)");
这是假设idperiode
是您的主键。如果主键由(idperiode,idjour)
组成,则必须调整ON
子句以及匹配时的,然后相应地更新SET
子句:
-- [...]
ON src.idperiode = dst.idperiode
AND src.idjour = dst.idjour
WHEN MATCHED THEN UPDATE SET
dst.heure = src.heure
-- [...]
您正在尝试将数据从一个表迁移到另一个表吗?不确定我是否理解您的问题。您是否正在寻找使用合并
的方法?我不是sql server用户,但已找到。