update column from other table

  • Hi,
    I want to update column ID from table TEMP_ID using table ABC, how should I update this?

    As In scenerio real I have to update 945455 records.  

    CREATE TABLE ABC
    (ID INT)

    INSERT INTO ABC VALUES (123)
    INSERT INTO ABC VALUES (456)
    INSERT INTO ABC VALUES (879)
    INSERT INTO ABC VALUES (157)

    CREATE TABLE TEMP_ID
    (ID INT)

    Thanks,
    Kiran

  • kiran.rajenimbalkar - Monday, July 9, 2018 2:23 AM

    Hi,
    I want to update column ID from table TEMP_ID using table ABC, how should I update this?

    As In scenerio real I have to update 945455 records.  

    CREATE TABLE ABC
    (ID INT)

    INSERT INTO ABC VALUES (123)
    INSERT INTO ABC VALUES (456)
    INSERT INTO ABC VALUES (879)
    INSERT INTO ABC VALUES (157)

    CREATE TABLE TEMP_ID
    (ID INT)

    Thanks,
    Kiran

    Hi Kiran,

    Can you kindly elaborate more on what you want exactly. So on what criteria you need update from ABC into TEMP_ID table.


    This will copy all the records from ABC into TEMP_ID table.

    CREATE TABLE ABC
    (ID INT)

    INSERT INTO ABC VALUES (123)
    INSERT INTO ABC VALUES (456)
    INSERT INTO ABC VALUES (879)
    INSERT INTO ABC VALUES (157);

    CREATE TABLE TEMP_ID
    (ID INT);

    INSERT TEMP_ID (ID)
    SELECT ID FROM ABC;
    ------------------------------------------------
    SELECT ID FROM  TEMP_ID;

    Saravanan

  • If the 2 tables have some value in common such as ID here, then you can do a join in the UPDATE statement, from your example though it isn't clear what value you are updating from one table to the next.  The basic structure of the UPDATE would look something like this:
    UPDATE a SET columnname = t.columnname
    FROM ABC a
      INNER JOIN TEMP_ID t ON a.ID = t.ID

    You may want to find a way to break down the work though since you said you have nearly a million records.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply