Solved

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

Posted on 2014-09-26
5
81 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

15 Experts available now in Live!

Get 1:1 Help Now