Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy table data from live to dev server

Posted on 2011-09-26
4
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Accepted Solution

by:
marappan earned 2000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

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 part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

661 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