Two possibilities that I can think of, and personally I would prefer option #1 below.1. Run all your queries/scripts from the imported database and explicitly refer to the main database in the scripts, do not refer explicitly to the imported database. Something like this:USE XYZDatabaseGOINSERT INTO MainDatabase.dbo.Table1SELECT * FROM dbo.Table1;
2. Use dynamic SQL, and run it from the main database:DECLARE @sql NVARCHAR(4000);DECLARE @databasename NVARCHAR(255);SET @databasename = 'XYZDatabase';SET @sql = 'INSERT INTO dbo.Table1 SELECT * FROM ' + QUOTENAME(@databasename) + '.dbo.Table1';sp_executesql @sql;