我找到了一种使用此模板使来自不同数据库的两个表相互匹配的方法:
INSERT [DestDB].[dbo].[TABLE]
SELECT source.* FROM
[SourceDB].[dbo].[TABLE] AS source
LEFT OUTER JOIN
[DestDB].[dbo].[TABLE] AS dest
ON
source.[PKColumn] = dest.[PKColumn]
WHERE dest.[PKcolumn] IS NULL
UPDATE dest
SET
dest.[PK_COLUMN1] = source.[PK_COLUMN1]
,dest.[COLUMN2] = source.[COLUMN2]
,dest.[COLUMN3] = source.[COLUMN3]
,dest.[COLUMN4] = source.[COLUMN4]
,dest.[COLUMN5] = source.[COLUMN5]
,dest.[COLUMN6] = source.[COLUMN6]
,dest.[COLUMN7] = source.[COLUMN7]
,dest.[COLUMN8] = source.[COLUMN8]
FROM
[SourceDB].[dbo].[TABLE] AS source
INNER JOIN
[DestDB].[dbo].[TABLE] AS dest
ON source.[PK_Column1] = dest.[PK_Column1]
但是,我正在使用的某些表至少有 200 列,虽然可以通过复制 + 粘贴的功能来做到这一点,但我只需要知道是否有一种方法不会让我患上 Carpel Tunnel Syndrome。
我正在使用 Microsoft SQL Server 2005。
有什么建议吗?