我有桌子
Employee
{
EmpId,
FirstName,
LastName,
DeptId
}
Department
{
DeptId,
DeptName,
Specialization
}
现在我已将专业化列添加到Employee
,所以现在新的Employee
表是:
Employee
{
EmpId,
FirstName,
LastName,
DeptId,
Specialization
}
现在我想要更新脚本将专业化数据从Department移到Employee
。
答案 0 :(得分:1)
您可以使用update-join语法:
UPDATE e
SET e.Specialization = d.Specialization
FROM Employee e
JOIN Department d ON e.DeptId = d.DeptId
答案 1 :(得分:0)
您可以使用简单的嵌套查询;
Update Employee Ee
Set Specialization = (SELECT Specialization
FROM Department Dpt
Where Dpt.DeptId = Ee.DeptId)