且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

合并到1数据表与相同的行数2数据表。

更新时间:2023-10-08 14:07:34

不知道更多有关这些表的设计,一些这是炒作。

Without knowing more about the design of these tables, some of this is speculation.

这听起来像您要执行的是加入。例如,如果你有一个表,该表是这样的:

What it sounds like you want to perform is a JOIN. For example, if you have one table that looks like:

StateId, StateName

和看起来像

EmployeeId, EmployeeName, StateId

和你想要的结果集,看起来像

and you want to end up with a result set that looks like

EmployeeId, EmployeeName, StateId, StateName

您将执行以下查询:

SELECT Employee.EmployeeId, Employee.EmployeeName, Employee.StateId, State.StateName
FROM Employee
INNER JOIN State ON Employee.StateId = State.StateId

这给你一个结果,但不更新任何数据。再次,猜测你的数据集,我假设你的Employee表的版本可能类似于结果集:

This gives you a resultset but doesn't update any data. Again, speculating on your dataset, I'm assuming that your version of the Employee table might look like the resultset:

EmployeeId, EmployeeName, StateId, StateName

Statename的需要被填充。在这种情况下,你可以写查询语句:

but with StateName in need of being populated. In this case, you could write the query:

UPDATE Employee
SET Employee.StateName = State.StateName
FROM Employee
INNER JOIN State ON Employee.StateId = State.StateId

经测试,在SQL Server中。

Tested in SQL Server.