Search code examples
coldfusiondatasourcecfquery

Coldfusion: Move data from one datasource to another


I need to move a series of tables from one datasource to another. Our hosting company doesn't give shared passwords amongst the databases so I can't write a SQL script to handle it.

The best option is just writing a little coldfusion scripty that takes care of it.

Ordinarily I would do something like: SELECT * INTO database.table FROM database.table

The only problem with this is that cfquery's don't allow you to use two datasources in the same query.

I don't think I could use a QoQ's either because you can't tell it to use the second datasource, but to have a dbType of 'Query'.

Can anyone think of any intelligent ways of getting this done? Or is the only option to just loop over each line in the first query adding them individually to the second?

My problem with that is that it will take much longer. We have a lot of tables to move.


Solution

  • Ok, so you don't have a shared password between the databases, but you do seem to have the passwords for each individual database (since you have datasources set up). So, can you create a linked server definition from database 1 to database 2? User credentials can be saved against the linked server, so they don't have to be the same as the source DB. Once that's set up, you can definitely move data between the two DBs.

    We use this all the time to sync data from our live database into our test environment. I can provide more specific SQL if this would work for you.