Copy data from one column to other column (which is in a different table)

后端 未结 8 1430
小鲜肉
小鲜肉 2020-11-30 20:59

I want to copy data from one column to another column of other table. How can I do that?

I tried the following:

Update tblindiantime Set CountryName          


        
相关标签:
8条回答
  • 2020-11-30 21:52

    Now it's more easy with management studio 2016.

    Using SQL Server Management Studio

    To copy data from one table to another

    1.Open the table with columns you want to copy and the one you want to copy into by right-clicking the tables, and then clicking Design.

    2.Click the tab for the table with the columns you want to copy and select those columns.

    3.From the Edit menu, click Copy.

    4.Open a new Query Editor window.

    5.Right-click the Query Editor, and then click Design Query in Editor.

    6.In the Add Table dialog box, select the source and destination table, click Add, and then close the Add Table dialog box.

    7.Right-click an open area of the the Query Editor, point to Change Type, and then click Insert Results.

    8.In the Choose Target Table for Insert Results dialog box, select the destination table.

    9.In the upper portion of the Query Designer, click the source column in the source table.

    10.The Query Designer has now created an INSERT query. Click OK to place the query into the original Query Editor window.

    11.Execute the query to insert the data from the source table to the destination table.

    For More Information https://docs.microsoft.com/en-us/sql/relational-databases/tables/copy-columns-from-one-table-to-another-database-engine

    0 讨论(0)
  • 2020-11-30 21:54

    Table2.Column2 => Table1.Column1

    I realize this question is old but the accepted answer did not work for me. For future googlers, this is what worked for me:

    UPDATE table1 
        SET column1 = (
            SELECT column2
            FROM table2
            WHERE table2.id = table1.id
        );
    

    Whereby:

    • table1 = table that has the column that needs to be updated
    • table2 = table that has the column with the data
    • column1 = blank column that needs the data from column2 (this is in table1)
    • column2 = column that has the data (that is in table2)
    0 讨论(0)
提交回复
热议问题