Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to insert and update from remote linked server Expand / Collapse
Author
Message
Posted Sunday, September 23, 2007 2:28 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 17, 2014 6:57 AM
Points: 55, Visits: 159
Comments posted to this topic are about the item How to insert and update from remote linked server
Post #401535
Posted Tuesday, October 30, 2007 7:45 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, May 31, 2013 11:53 AM
Points: 10, Visits: 23
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.

Post #416514
Posted Wednesday, October 31, 2007 2:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, March 9, 2012 3:33 AM
Points: 5, Visits: 42
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.
Post #416921
Posted Wednesday, October 22, 2008 9:32 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, July 17, 2014 6:57 AM
Points: 55, Visits: 159
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







Post #589885
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse