我需要将表A的a列的值复制到表B的b列中。
这句话是否正确?
UPDATE
TableA,
TableB
SET
TableB.b = TableA.a
WHERE
TableA.Id = TableB.Id
答案 0 :(得分:0)
一种解决方案是在FROM
JOIN
和UPDATE
UPDATE A
SET A.a= B.b
FROM TableA A
JOIN TableB B ON A.ID = B.ID
答案 1 :(得分:0)
如果目的地的列为空并且您不需要匹配某些内容,请使用此
INSERT INTO DestinationTb ([ColumnName])
SELECT [ColumnNameToTransfer] FROM [SourceTable]
如果不只是加入
update A
SET A.Columnname = B.ColumnNameToTransfer
from DestinationTb A
INNER JOIN
SourceTable B
ON
--HERE ADD YOUR MATCHING FOR EXAMPLE
A.ID = B.ID;
或使用子查询
UPDATE DestinationTb
SET ColumnName = (
SELECT ColumnNameToTransfer
FROM SourceTable
--HERE ADD YOUR MATCHING FOR EXAMPLE
WHERE SourceTable.id = DestinationTb.id
);