0

我将以下记录从 excel 导入数据库。记录数为 5,00,000。

EmpId Name City CityId

1 Ramesh LA ?

2 Kumar NewYork ?

我需要从其他表中获取 CityId 并插入到这个表中CityId

另一个表具有城市的别名和 cityId

CityId AliasName

1 LA

1 LosAngels

1 Los Angels

1 LA(USA)

我想调用一个存储过程来更新所有 500000 条记录,因为函数不能用于更新记录。

我需要为 Alias Table 中的每个员工更新 CityId 字段

4

4 回答 4

1

您可以执行以下操作:

     update employee
     set cityid = b.cityid
     from employee as a inner join city as b on a.city = b.aliasname
于 2013-07-05T09:38:09.543 回答
0

Would it not be easier to set the City as a foreign key rather than adding a redundant data column.

To answer your question, you can achieve this by running the following query. You can also make this into a stored procedure if it needs to be run occasionally.

UPDATE Employees SET CityId = (Select CityId FROM Cities where AliasName = City)
于 2013-07-05T09:49:31.910 回答
0

以下查询将更新所需的数据:

UPDATE Employees SET CityId = ISNULL((Select CityId FROM Cities where AliasName = City),0)
于 2013-07-05T10:01:27.480 回答
0

希望这可以帮助你。

UPDATE UserDetails
SET UserDetails.CityID = City.ID
FROM City
WHERE City.AliasName = UserDetails.City
于 2013-07-05T09:38:46.390 回答