Solved

Copy table data from live to dev server

Posted on 2011-09-26
4
212 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 39

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

763 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