Copy database to a new server - sql-server-2016

Is it possible to copy a database to a new server? I just want to have the database on a new server because I need to make some tests. I didn't have much experience with servers.

Follow this steps :
Run your SSMS
Right click on the database you want to copy
In the Popup menu , go to Taches , then click Offline
Right click on the Database again in the popup menu , Taches -> Detach
Open the folder ..\MSSQL\DATA , copy Yourdb.MDF and YourDB_log.LDF files to the folder of the new Instance.
Now you can Attach both Databases and work on it in both instance.
Another way:
Run Your SSMS
Right click on the Database you want to copy
In the popup menu , Taches -> Copy the database...
Follow the steps on the Wizard
You can select option if you want to keep the database ONLINE when it is being copied.
You can also select option of MOVE or COPY database as well.
When the process is over it will show the success message and database will be copied to another server.
Note:
1- The Copy Database Wizard is not available in the Express edition.
2- The Copy Database Wizard cannot be used to copy or move databases that are/have:
System.
marked for replication.
marked Inaccessible, Loading, Offline, Recovering, Suspect, or in Emergency Mode.
data or log files stored in Microsoft Azure storage.
Also , a database cannot be moved or copied to an earlier version of SQL Server.
Updtae:
If there is no Copy database option , then you can Copy Databases with Backup and Restore.
For more information about it MSDN.

No experience? No problem, backup the database.
Copy it into the target machine.
Restore DB from device >> open the DB backup file.
At this point you have the entire DB without missing any schema objects such as foreign keys.
Finally delete all sql logins that the DB came with and recreate them manually as you test access.
Once you are comfortable with this operation you can go ahead and get more experience using some of the techniques describe above which are recommended if you have a large DB to restore and so on.
How to restore the DB on SQL Server Management Studio
Steps:
1. On “Object Explorer” panel right-click on “Databases” and selected Restore Database
Select “Device” and browse database location.
note: Copy the .bak file locally before restoring.
The DB information will auto-populate the window, you can edit the name of the DB to be restored.
Go to the “Files” page and check the “Relocated all files…” box.
Select existing folder locations for Data and Log files.
HIT OK

Related

Creating a local database from server database in visual studio

I have a rather large database I am working with and I am about ready to break something. To prevent this affecting live data, how would I use the live database to setup a local database? Not sure if this is even possible but I do know you can setup a local db.
You can create a SQL Server Data Tools database project type, then right click the project file and do an "Import..." to import the database to your local machine. Then you can deploy the local DB and it will be available in the SQL Server Object Explorer locally. This way you don't have to install SQL server on your machine - everything's in Visual Studio. Hopefully you are developing with a small set of data locally.
Answer
Use Visual Studio's Data Comparison tool to synchronize data to your target database from your source after you've created the database (schema only, no data) in your local database server.
Steps
From the Visual Studio's SQL Server Object Explorer:
A. Create the local database
Add two SQL Server Objects: One that connects to your production server and one that connects to a local (development/testing) server. If you need help setting up a local server then take a look at SQL Server LocalDB
Add a New database in your local server to receive the data (don't over think this step).
B. Migrate the Schema
Right-click the source (production) database and click Schema Compare...
From the SQlSchemaCompare tab that opens, use the Select Target dropdown to select your local database as the target.
From the SQlSchemaCompare tab, click Compare.
Uncheck everything in the comparison results except for the Tables, Views, and Procedures (unless you know what you're doing) then click Update.
C. Migrate the Data
Right-click the source (production) database and click Data Comparison...
Follow through the prompts to select the Tables to migrate then click Finish.
From the SQlDataCompare tab that opens, review the comparison results (it should make sense to you) then click Update Target
That's it! Either your local database is ready with data, or you confused your target/source and wiped out all of your data in production. Either way, you're done for the day.

How to copy database in ssms Express version

I just now joined my first job (two days ago) and I am using Microsoft sql server management studio express version here. I want to create a new database by copying data, indexes and all properties from production database(We don't have a QA database) so that I can practice on it. How can I do that. I tried by taking backup of prod db and importing it into new database but it didn't worked and I got this error:
.
I am using Express version so no copy database option.
This might be a possible duplicate of this question: ssms copy database but I am using express version.
Can somebody tell me how can I do this.
Thanks
This is not hard to do in SSMS when working with SQLEXPRESS databases. I just executed these steps myself to verify that it works.
Create a full backup of the database you want to duplicate. To do this, right click on the database you want to duplicate, select Tasks, then Back Up .... Accept the defaults (or alter them if you wish) and click the "OK" button.
Now we will restore this backup to a new database. In SSMS, right click on the Databases folder icon. Choose Restore Database .... In the To database: text box, give your new database a name. I used "test". The name should not duplicate the name of any existing database. In the From database: dropdown, select the backup you created in Step 1. Click the "OK" button.
You should now have a copy of your original database, and it is named "test". To see it you may need to right click on the Databases folder icon and choose Refresh.
Hope it helps. Good luck!

SQL 2005 Moving from Godaddy SQL Server to a company owned server

What is the best way to go about moving a database from a Godaddy SQL 2005 account to a local SQL 2005 server? I have access to the DB through Server Management Studio Express and also through the Godaddy SQL explorer.
However, I have no idea where to start. In MySQL, I would just export the data through the PHPMyAdmin page, and conversely import it on the other server using an ASCII file. In access, I'd just use the migrate tool. In Server Management Studio, I've thought about using the "Backup" and "Restore" method, but I'm afraid that I won't have the ability to create a new object with the correct permission schema on the new server.
What are your thoughts? Keep in mind that I do not have access to the MDF or temp files. I've been studying this page.
SMSS should be able to do it for you. If you are looking to move the entire database and not just a few tables, the Backup and Restore method is probably your best bet.
Your steps might include:
connect to Godaddy sql server in ssms
Right click the database you want to move and select Tasks > Backup
Keep/set Backup type = "Full" and add a destination at the bottom that you will be able to access.
After backup completes, move the .bak file to a location that your local sql server can see.
Connect to your local sql server in ssms.
Right click Databases > Restore Database
Enter the database name you want in "To Database:"
Select "From device:" and locate the .bak file you created before.
In the row that shows up in the grid display, check the restore check box.
If it matters to you where the recreated files will be stored, select options on the top left menu and confirm the file locations under the "Restore As" column in the data grid.
Click ok and the restore should start.
To migrate users, follow the directions at http://support.microsoft.com/kb/918992
Don't be so afraid of the backup and restore. You have a much better chance at getting a high fidelity copy of your data than trying to roll your own. Give it a shot, test it out, and see what happens. I think you'll be pleasantly surprised.

transfer SQL database (table and data)

iv created a database with some tables and populated them using SQL server 2008, i want to move the database to another machine, what would be the best way copy the database and recreate it in another location ??
by the way im connecting to localhost\SQLEXPRESS if thats important !!
thanks
Backup and restore is usually the simplest way. The only complexity you may encounter is that your may have to recreate and associate users on your target system.
Do a backup of your database and then restore it on another machine
Right click on your database in SSMS. Choose Tasks->Backup. Then choose your location and click ok. Take the backup file you create out of the folder it was in and put it into the same folder on your other computer. Then open SSMS on your other machine. Right click on the database folder and click Restore Database. Enter what you ant to name it, choose From Device and then find your file. Click OK and you are done.
I would use SQL Server backup and restore. I believe you can backup in SQLExpress (you just can't schedule one).
Right click your database, and select Tasks -> Backup. Do the backup.
On your other sql server instance create a database with the same name. And do Tasks -> restore -> database
If you have permissions to restore on the target database server then that is by far the best way to copy the database.
If you don't have permissions, then you'll want to connect to the source and target databases with Management Studio and Import the data from the source. If you have simple primary key only indices on your tables you can import by right clicking on the target database name, then select Tasks, then Import Data. A wizard will walk you through it.
You can practice by importing the data into a new database on your local machine first.
If you have more complex indices or functions, sprocs, and views, you'll want to create the new database first, before you import the data. Same procedure, but select Generate Scripts. The wizard will walk you through the necessary steps. Under script options you'll want to make sure you select True for Script Indexes.
Again you can practice by recreating and importing locally. Though if you create locally you'll need to give the database a new name.

How to copy a SQL 2005 database to another computer?

I'm trying to rebuild a web server in a virtual pc. Installed required software and Microsoft SQL Server 2005. I've had full backups of my databases but it is not possible to restore from those backups in this new installation. By the way, backups are fine, i can restore from them on original server.
In summary, how can I copy whole database to another computer? How can I backup a database and restore is fully on another computer?
Regards,
Burak
PS: The database I'm trying to restore is called "Some_db" and it does not exist on new server. I also tried to create a new one with defaults and restore on it but that gave an error on new db. I don't know any details of the database.
You have 3 Choises:
1) Restore DB as you tried
This failed for you for some reason
Here a tutorial: http://msdn.microsoft.com/en-us/library/ms177429.aspx
2) Detach DB and Atach it to the new server
This is easy: Rightclick on the DB -> Detach.
Rightclick on the new Server -> Attach
Tutorial: http://www.databasedesign-resource.com/moving-the-database.html
3) Create Create-Scripts of the table schema and use insert into statements for the data.
For this, there are a bunch of tools, my favourit is "Redgate SQL Compare".
It creates you all nessecary scripts.
The link: http://www.red-gate.com/products/SQL_Compare/index.htm
Backup file
Copy .bak file to other server
Restore .bak file.
Works every time for me. You have to make sure the new instance of SQL is of a sufficient level to be able to host the database. You also have to recreate the users on the new server and remove and readd them to each database.
The alternative to the backup and restore approach is to detach the db, copy the mdf and ldf files over and then attach them on the new server
Or take offline, copy files, attach database, bring online..
open your current query browser window and run the query .The restore will happen automatically
BACKUP DATABASE AdventureWorks
TO DISK = 'C:\Backup\AdventureWorks.bak'
GO
for more details
This will create a .bak file after that copy the .bak to server.
restore the data base by right click on DataBase .Select restore database .Give the database name and location .And restore it .