Solved

Copy table data from live to dev server

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sorting a SQL script 5 42
What is GIS method of Geometry data type? 6 36
TDE for SQL Web Edition 1 42
Need help with part of sql query for a condition 12 36
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…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

752 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