Bulk Record Update with SQL

前端 未结 5 1466
你的背包
你的背包 2020-12-05 02:48

I have two tables in a SQL Server 2008 environment with the following structure

Table1
- ID
- DescriptionID
- Description

Table2
- ID
- Description
<         


        
5条回答
  •  余生分开走
    2020-12-05 03:19

    The SQL you posted in your question is one way to do it. Most things in SQL have more than one way to do it.

    UPDATE
      [Table1] 
    SET
      [Description]=(SELECT [Description] FROM [Table2] t2 WHERE t2.[ID]=Table1.DescriptionID)
    

    If you are planning on running this on a PROD DB, it is best to create a snapshot or mirror of it first and test it out. Verify the data ends up as you expect for a couple records. And if you are satisfied, run it on the real DB.

提交回复
热议问题