You can run the command from any database if you fully qualify the names. For example, it wouldn't matter where you run the command from:-- Database B is where you have the table to store the infoINSERT INTO DatabaseB.dbo.Counter_Matrix (col1,col2,col3)SELECT colA,colB,colC FROM DatabaseA.dbo.PerformanceTable;
Alternatively, and especially if you are using views, functions, tables etc. from the production database you can change to the production database and then run it:USE DatabaseA -- Production databaseGO-- Database B is where you have the table to store the infoINSERT INTO DatabaseB.dbo.Counter_Matrix (col1,col2,col3)SELECT colA,colB,colC FROM dbo.PerformanceTable;
Hope that is what you are asking :)