Solved

Copy table data from live to dev server

Posted on 2011-09-26
4
209 Views
Last Modified: 2012-06-27
I have two existing Product tables -- one on our dev server, one on our live server.

I would like to essentially "copy down" all the Products FROM the live server to dev, getting rid of all the product data that is currently in the dev table.

How can I copy the products from live to dev, so that the primary keys (int) are all the same etc?
0
Comment
Question by:mandi224
4 Comments
 
LVL 2

Accepted Solution

by:
marappan earned 500 total points
ID: 36599765
1) Truncate table Product on Dev

2) A) Use SSIS package for copying the table from production to development environment. (OR)
    B) Create linked server on development server and use the below statement for copying Product table:

             INSERT INTO PRODUCTTABLE SELECT * FROM PRODUCTIONSERVER.DB1.PRODUCTTABLE

   (OR)
    c) Use OPENROWSET

Below is the link for using linked server or OPENROWSET:

http://www.techrepublic.com/blog/datacenter/how-do-i-query-foreign-data-using-sql-servers-linked-servers/133

Since we are truncating the product table in development environment, we dont have to worry about same primary key unless you have used identity column.
0
 
LVL 5

Expert Comment

by:JAT-DBA
ID: 36599910
You should consider 2.A from marappan suggestion above.
I don't know how tight your production environment is but i do not ever allow linked servers on development servers to be defined agains a production environment.

In regards to the truncate statement  I want to expand on the statement by marappan.
The use of truncate on a table with a identity column will cause a reset of the identity seed back to the base value of when the table was created which in most cases would be 1.

So if you are testing inserts and your identity column has a unique index or is the primary key the insert will fail if there is already a record with that value

You will need to either reseed the value (see BOL for DBCC CHECKIDENT) or enable identity insert as part of your ssis package.
0
 
LVL 38

Expert Comment

by:Aaron Tomosky
ID: 36599912
If it's not too huge, I find it easiest to do a restore from database. in ssms right click databases, restore, from db.
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36600686
why the requirement to maintain keys?

the two environments are separate so you would expect the keys to be different...

if you want to maintain keys ,,, then don't you have a bigger problem in development in that you will need to remap all your other dependant tables  which use the product key...
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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…
In this article I will describe the Detach & Attach 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.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

770 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