For the company's project transformation, we need to import the previous database table records to the new database table. The structure is not exactly the same.
Many things have been learned in the Cross-database process. It turns out that sqlserver has the function of linking servers.
/* Data operations between different Server databases */
-- Create a linked server
ExecSp_addmediaserver'Itsv','','Sqlodb','Remote server name or IP address'
ExecSp_add1_srvlogin'Itsv','False',Null,'Username','Password'
-- Query example
Select*FromItsv. Database Name. DBO. Table Name
-- Import example
Select*IntoTableFromItsv. Database Name. DBO. Table Name
-- Delete the linked server when it is no longer in use
ExecSp_dropserver'Itsv','Droplogins'
My tests:
ExecSp_addmediaserver'Srv _ lnk','','Sqlodb','192. 168.1.x1'
ExecSp_add1_srvlogin'Srv _ lnk','False',Null,'Sa','Sa'
InsertIntoCounterdb. DBO. Sites (sitekey, parentid, name)
SelectBarid, areacode, barnameFromSrv_lnk.testcounter.dbo.site
InsertIntoCounterdb. DBO. countdata
(Camerakey, counttime, innum, outnum, refix, exportflag, changeflag)
Select Top(200000) camerano, datetime, up, down, refix
FromSrv_lnk.testcounter.dbo.counter_table
ExecSp_dropserver'Srv _ lnk','Droplogins'