Move a database from one server to another server in SQL Server 2008

There are many ways to move/copy a database from one server to another server using SQL Server Tools.

i) Detach the database from the old server and attach it in the new server. This is purely offline operation and it moves the database instead of copying it.

Refer https://msdn.microsoft.com/en-us/library/ms190209.aspx : how to use attach/detach database in SQL Server Management Studio(SSMS)

ii) Back up the database in the old server and restore it in the destination server. This can be performed during online and it creates a new database in the destination server.

Refer https://msdn.microsoft.com/en-us/library/ms187048.aspx for more information.

iii) Using copy database wizard in SQL Server Management Studio.

Select the database in the source server in SSMS
Right click ->Tasks->Copy Database Wizard to launch the copy database wizard.
Enter the source and destination credentials and select either attach/detach or SMO type
click next and you can schedule or run immediately
Click finish to execute it

Refer https://msdn.microsoft.com/en-us/library/ms188664.aspx for more information.

iv) The last type is to generate the create script using Generate Script Wizard (SSMS)  and execute it in the destination server.

Select the database in the source server in SSMS
Right click ->Tasks->Generate Scripts Wizard to launch the wizard.
Select the various scripting options needed and select the objects needed to generate the scripts for them. Make sure script data = true in the scripting option to generate script for data as well (INSERT statements)

click next ->next and finish to generate the script (new query window or clip board or file)
connect to the destination server and create the new database in it.
Click new query window and paste the script generated using GSW above and execute them with the destination database context.

Refer https://msdn.microsoft.com/en-us/library/ms181421.aspx for more information

v) Using Transfer Object in SMO

Sample code:
ScriptingOptions so = new ScriptingOptions();
so.ScriptData = true;
Transfer t = new Transfer(db);
t.CopyAllObjets = true;
t.options = so;
...................
..................
 t.TransferData();

Note: Transfer class is available in Microsoft.SqlServer.SmoExtendedClass.dll  (SQL Server 2008)
or Microsoft.SqlServer.Smo.dll (SQL Server 2005)

There are various member variables to be configurable. Also ScriptingOptions class object can be created and assigned to the transfer object as well.

set ScriptData = true in order to transfer data also. It copies the destination instead of moving the database

Refer  https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.transfer.aspx for more information.

vi) You can make use of Database Publishing Wizard to accomplish this. You can specify the target version as SQL 2005 or SQL 2000 etc as per your requirement.