September 23, 2007 at 2:28 am
Comments posted to this topic are about the item How to insert and update from remote linked server
October 30, 2007 at 7:45 am
It would seem the post ends with :
Create a districtid column in the 'replication tables' and make it a composite key.
for example:
USE [DIMSCONSOLIDATEDData]
G
I'd like to see the rest of the example or post so I can try this out on a project that could use it.
October 31, 2007 at 2:54 am
I noticed that you are using SQL 2005, so SSIS (SQL Server Integration Services) will be the best choice here, but if you wish to continue with same logic then I recommend the following changes.
> Create a new stored procedure by name ScriptGenerator, let it loop through district-tables (alias information) and form all the Insert and Update statements. And let it alter the actual stored procedure created by you and feed all the newly created Insert and Update statements. By this way you will gain a huge performance benefit.
So rather than calling
exec 'insert into xyz values (1,2,3)'
you will find a direct executable statement in your SP
insert into xyz values(1,2,3)
> You might have already taken this into condieration, but try to remove any indexes if possible from the new storage place, having indexes takes more time for insert and update.
October 22, 2008 at 9:32 am
unfortunately at the time i published this article the data was truncated when i submitted it. unfortunately that stuff is long gone.
basically it worked like this:
i had a table that mapped the remote sql server (linked server) to the district id that it was associated with.
then i had a bunch of stored procedures, one for each table that needed an import or update, in all of these stored procedures i had a districtid input parameter, which was resolved to the linked server name it belonged to by a user defined function.
from the the dynamic sql was constructed for example:
if district id was 1 then
insert into localtable (columnlist plus the districtid) select (exact same column list plus the districtid) from [(linkedserverremotetable(fully qualified name))] where [(remotecriteria)] not in (sub query localtable).
the update works similarly.
now i had something like 200 stored procedures doing this.
i wrapped them all up in a stored procedure that used a cursor to go through all the districtid's in the linkedsever table and execute them in order.
when i tested it on a local environment it worked very well and it to approximately 2 minutes to import about 2 million records.
this was my first piece of 'advanced' sql.
if i had to do it again i would change some things slightly, and probably use other technology.
however this logic did work, and if the technology is not avialiable (i.e you dont have enterprise licences or have older technology)
it is a real shame that my article was truncated. it was eleven word pages long, orginally. i have lost it long ago.
thanks
Chris
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply