Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to insert and update from remote linked server


How to insert and update from remote linked server

Author
Message
kodracon
kodracon
Valued Member
Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)

Group: General Forum Members
Points: 73 Visits: 162
Comments posted to this topic are about the item How to insert and update from remote linked server
Gary Gerard
Gary Gerard
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 24
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.
Mohd Faraz
Mohd Faraz
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
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.
kodracon
kodracon
Valued Member
Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)

Group: General Forum Members
Points: 73 Visits: 162
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search