Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy data records between two instances of an SQLServer database

I need to copy some records from our SQLServer 2005 test server to our live server. It's a flat lookup table, so no foreign keys or other referential integrity to worry about.

I could key-in the records again on the live server, but this is tiresome. I could export the test server records and table data in its entirety into an SQL script and run that, but I don't want to overwrite the records present on the live system, only add to them.

How can I select just the records I want and get them transferred or otherwise into the live server? We don't have Sharepoint, which I understand would allow me to copy them directly between the two instances.

like image 982
Jaymie Thomas Avatar asked Sep 30 '08 17:09

Jaymie Thomas


People also ask

How do I copy records from one database to another database?

Right-click on the database name, then select "Tasks" > "Export data..." from the object explorer. The SQL Server Import/Export wizard opens; click on "Next". Provide authentication and select the source from which you want to copy the data; click "Next". Specify where to copy the data to; click on "Next".

How copy data from one database to another in SQL?

Using SQL Server Management StudioClick the tab for the table with the columns you want to copy and select those columns. From the Edit menu, click Copy. Click the tab for the table into which you want to copy the columns.


2 Answers

If your production SQL server and test SQL server can talk, you could just do in with a SQL insert statement.

first run the following on your test server:

Execute sp_addlinkedserver PRODUCTION_SERVER_NAME 

Then just create the insert statement:

INSERT INTO [PRODUCTION_SERVER_NAME].DATABASE_NAME.dbo.TABLE_NAME   (Names_of_Columns_to_be_inserted) SELECT Names_of_Columns_to_be_inserted FROM TABLE_NAME 
like image 100
Kwirk Avatar answered Oct 02 '22 14:10

Kwirk


I use SQL Server Management Studio and do an Export Task by right-clicking the database and going to Task>Export. I think it works across servers as well as databases but I'm not sure.

like image 24
Joe Phillips Avatar answered Oct 02 '22 15:10

Joe Phillips