Solved

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

Posted on 2014-09-26
5
82 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:ScottPletcher
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:
ScottPletcher 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now