用于将数据从一个表合并到另一个表的 T-SQL

Tar*_*kus 1 sql sql-server sql-server-2008

假设有 2 个表 Table1 { ID, Name, Other } 和 Table2 { ID, Name, Other }。它们都具有相同 ID 的相同记录,只是在 Table1 中所有 Name 值都是 NULL。如何使用 T-SQL (SQL Server 2008) 将 Name 值从 Table2 导入到 Table1?

Jas*_*yon 5

Update Table1
Set Table1.Name = Table2.Name
From
Table1 INNER JOIN Table2 on Table1.ID = Table2.ID
Run Code Online (Sandbox Code Playgroud)