Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transfer data from one database to another database

How to fetch the data from one database and insert in to another database table? I can't to do this. Please help me in transferring data from one to another.

like image 539
Bharathi Avatar asked Apr 05 '12 12:04

Bharathi


People also ask

How do I copy data from one database table to another database in SQL?

Using SQL Server Management StudioOpen the table with columns you want to copy and the one you want to copy into by right-clicking the tables, and then clicking Design. Click the tab for the table with the columns you want to copy and select those columns. From the Edit menu, click Copy.

How do I restore data from one database to another in SQL Server?

Connect to the appropriate instance of the SQL Server Database Engine, and then in Object Explorer, click the server name to expand the server tree. Right-click Databases, and then click Restore Database. The Restore Database dialog box opens. Select the database to restore from the drop-down list.

How do I copy records from one database to another?

A simple way is to open SSMS and Right click on database and go to Tasks > Import Data and follow the wizard to set source and destination. This way if data exists on different systems and even if you wish to change structure you can do. Also append, or cleanout data at same time from destination.


2 Answers

There are several ways to do this, below are two options:

Option 1 - Right click on the database you want to copy

  • Choose 'Tasks' > 'Generate scripts'

  • 'Select specific database objects'

  • Check 'Tables'

  • Mark 'Save to new query window'

  • Click 'Advanced'

  • Set 'Types of data to script' to 'Schema and data'

  • Next, Next

You can now run the generated query on the new database.

Option 2

  • Right click on the database you want to copy

  • 'Tasks' > 'Export Data'

  • Next, Next

  • Choose the database to copy the tables to

  • Mark 'Copy data from one or more tables or views'

  • Choose the tables you want to copy

  • Finish

like image 141
Virus Avatar answered Oct 05 '22 16:10

Virus


Example for insert into values in One database table into another database table running on the same SQL Server

insert into dbo.onedatabase.FolderStatus (   [FolderStatusId],   [code],   [title],   [last_modified] )  select [FolderStatusId], [code], [title], [last_modified] from dbo.Twodatabase.f_file_stat 
like image 43
Lokanathan Avatar answered Oct 05 '22 15:10

Lokanathan