Solved

Using Stored Proceedure to Copy Table Data from Server A to Server B

Posted on 2014-09-26
5
85 Views
Last Modified: 2014-10-16
USE [MyDatabaseABC]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[uspUpdateTableData]
AS
DELETE FROM MyDatabaseABC.CustomerInformation;
INSERT INTO MyDatabaseABC.dbo.CustomerInformation
SELECT * FROM MyOtherDatabase.dbo.CustomerInformation;

The issue is the SELECT * FROM is a different server. How do I code this to look at a different server? Can  I do this? My goal is to remove all data and repopulate it with data from a different server. The new data is SQL 2008 the old data is on SQL 2005
0
Comment
Question by:allenkent
  • 2
  • 2
5 Comments
 
LVL 11

Assisted Solution

by:John_Vidmar
John_Vidmar earned 250 total points
ID: 40346938
A 4-part object reference should do the trick:

USE [MyDatabaseABC]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[uspUpdateTableData]
AS
DELETE FROM MyDatabaseABC.CustomerInformation;
INSERT INTO MyDatabaseABC.dbo.CustomerInformation
SELECT * FROM OtherServer.MyOtherDatabase.dbo.CustomerInformation;
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 40350533
Be sure the data volume is low enough that you really want to do a delete and re-insert.  You could use Change Tracking, as one example, to just determine modifications (DELETE, INSERT, UPDATE) and apply those instead.  Or delayed replication, etc..
0
 

Author Comment

by:allenkent
ID: 40354968
I keep getting error:

Msg 102, Level 15, State 1, Procedure uspUpdateTableData, Line 5
Incorrect syntax near '-'.
0
 

Author Comment

by:allenkent
ID: 40354979
My server name is:   DD-01   (it has a dash). Is that the issue?
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 40355005
Yes.  Put brackets around the server name; for example:


SELECT * FROM [DD-01].MyOtherDatabase.dbo.CustomerInformation;
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question