Solved

Copy table data from live to dev server

Posted on 2011-09-26
4
205 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Creating Alerts in sql sever 2 12
SQL Server creating a temp table 7 25
Mssql SQL query 14 24
BULK LOGGED - log full 9 11
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

762 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

9 Experts available now in Live!

Get 1:1 Help Now