简体   繁体   中英

Copying SQL Server Data to another Database on another Server

I have installed a SQL Server database on my customer's server.

I have an exact duplicate database schema on my laptop to enable me to work on things whilst I am off site.

However I need to copy the actual data in the customers database into my copy on the laptop, in order to test a few things.

What is the easiest way of doing this?

The customer server and my laptop are not connected (although I have VPN access to the customer's server) so I do not believe I can do this with TSQL.

Is there a way to Export from SSMS and then Import into my laptop database?

Backaup your database and then restore on another server.

From MSDN:

RESTORE If the database being restored does not exist, the user must have CREATE DATABASE permissions to be able to execute RESTORE. If the database exists, RESTORE permissions default to members of the sysadmin and dbcreator fixed server roles and the owner (dbo) of the database (for the FROM DATABASE_SNAPSHOT option, the database always exists).

RESTORE permissions are given to roles in which membership information is always readily available to the server. Because fixed database role membership can be checked only when the database is accessible and undamaged, which is not always the case when RESTORE is executed, members of the db_owner fixed database role do not have RESTORE permissions.

For a similar situation, what I do is I take the customer database offline (detach), copy the file off to my laptop and re-attach the database back to the customer server.

Uses SSMs and right click the database and click detach. Be sure, no one is actively working on the database. Also be sure that you know the location of the mdf file and you have access to it. Once detached, copy the file off. Then go the SSMS, right-click on 'database' and select 'attach'. Select the mdf file again and you get the database back on the customer's server.

You can attach the mdf file you copied in the steps above into your own server instance.

The otherway will be taking a backup and restoring on your laptop.

Another option is to setup data repication. See details here

since you've mentioned that you can be connected through VPN, you can possibly copy the data from one server into another using INSERT INTO...SELECT , eg

INSERT INTO server2.database.dbo.tableName (col1, ..., colN)
SELECT col1, ..., colN
FROM server2.database.dbo.tableNam

or use Backup and Restore feature in SSMS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM