Migrate data from one DB1 table to another DB2 database table

Asked

Viewed 30 times

1

I have 2 databases on Sql Server DB_1 and DB_2 being DB_2 a clone of DB_1

I am trying to migrate all data from DB_2 Ignition table (older data) to DB_1 Ignition table (newer data) so that the data comes in an orderly manner

Example

DB_1

Table_Ignition
 IMEI  | TimeStamp  | Value |
123456 | 1581405980 | false |
123456 | 1581406335 | true  |
123456 | 1581413214 | false |
123456 | 1581413271 | true  |
123456 | 1581413274 | false |


DB_2
Table_Ignition
 IMEI  | TimeStamp  | Value |
123456 | 1577534767 | true  |
123456 | 1577534951 | false |
123456 | 1577535203 | true  |
123456 | 1577535266 | false |
123456 | 1577535287 | true  |

The end result would be something like

DB_1

    Table_Ignition
     IMEI  | TimeStamp  | Value |
    123456 | 1577534767 | true  |
    123456 | 1577534951 | false |
    123456 | 1577535203 | true  |
    123456 | 1577535266 | false |
    123456 | 1577535287 | true  |
    123456 | 1581405980 | false |
    123456 | 1581406335 | true  |
    123456 | 1581413214 | false |
    123456 | 1581413271 | true  |
    123456 | 1581413274 | false |

thought of creating an API to do this task.

There is something more practical to be done ?

  • @Ivanferrer mysqldump for SQL Server?

  • Opa, sqlserverdump was bad!

  • Why not to use sqlserverdump if both are equal?

1 answer

1

Ordering the data does not matter, you must explicitly define the order you want using the clause ORDER BY in the SELECT. To insert from one bank to another you perform the insertion in this way:

INSERT INTO [DB_1].[dbo].[Table_Ignition](IMEI, TimeStamp, Value)
SELECT IMEI,
       TimeStamp,
       Value
  FROM [DB_2].[dbo].[Table_Ignition]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.