SQL - copy one column from one database to another database. RRS feed

  • Question

  • Hello Everyone,

    I made bad update in my database (1 column)
    I can not restore from point in time :(

    I have backup (from 2 days ago)
    I restore file (database to local disk) but i dont make restore and lose my data.

    Now i have the same 2 databases and i need to copy 1 column form first databasee to my second database.

    How should i do this?

    Monday, December 4, 2017 8:56 AM

All replies

  • Hello,

    By using a three-part qualifier database.Schema.table to Access the table in the other database; join over PK and update the data.

    See also Using Identifiers As Object Names

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Monday, December 4, 2017 9:50 AM
  • Alternatively you can use SSIS or the SSIS embedded in SSMS if you prefer to copy the table from First DB to Second DB. Once you have the table you can update the column which need to be updated. Careful with the dates, you can update the column until two days before getdate() (when the backup was taken). So if in the table you have a date identity use that.

    Please mark as answer if this post helped you

    Monday, December 4, 2017 10:27 AM
  • Thank You all for answers.

    So what do you think about export file to xls/xlsx/csv and then import/uptade?
    I have 250 000 rows to update.
    Should I split update into parts?

    Which method will be the best (safe and fast) (Yours, my, other)?

    Monday, December 4, 2017 11:00 AM
  • The update up to you. As I've written before probably you must use the date as condition. To move the table you can use SSIS embedded in SSMS as below (Right Click on Second DB, Tasks, Import Data) :

    Please mark as answer if this post helped you

    Monday, December 4, 2017 11:08 AM