UPDATE table1 FROM table2(使用Sql Server Compact)

时间:2015-08-21 13:37:32

标签: sql sql-server sql-server-ce sql-server-ce-4

我想从[To]表中的行更新[From]表中的行,其中键是相等的。所以这就是我要做的事情:

UPDATE [To]
SET    [To].[Name]      = [From].[Name],
       [To].[Size]      = [From].[Size],
       [To].[Something] = [From].[Something]
FROM   [From]
WHERE  [To].[Id] = [From].[Id];
go

问题是,CE doesn't support FROM in the UPDATE command

那么,如何更改此语法以在CE中工作?

2 个答案:

答案 0 :(得分:1)

尝试以下代码段(未经测试) -

UPDATE [To]
SET    [To].[Name]      = [From].[Name],
       [To].[Size]      = [From].[Size],
       [To].[Something] = [From].[Something]
WHERE EXISTS (SELECT 1 FROM [FROM] WHERE [To].[Id] = [From].[Id])

答案 1 :(得分:-1)

更新到 设置为.fld1 = from1.fld1 从table1到内部连接表from1 on to.id = from1.id