开发者

Most efficient way of transferring large amounts of data from one column to another?

I currently have two tables, a开发者_JS百科nd one has a dependency on the other that I want to remove. Let's say the tables are Product and Employee, and there are about 800,000 rows in each table.

The Employee table has a ProductID, in which there is a ProductRefID, which I need to reference in my application. The way this is done is to join in the Product table, and reference the ProductRefID that way.

However, I now want to change this so that ProductRefID is a column on the Employee table, and then transfer every Product row's "ProductRefID" to the Employee row's "ProductRefID".

What would be the most efficient way of writing this query?

(I know it sounds stupid, but it's just an example, it's not actually what I'm trying to do specifically).


Something like this ?

alter table Employee add ProductRefID INT


update e
set ProductRefID = p.ProductRefID
from Employee e
join 
Product p
on e.ProductID = p.id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜