Link to home
Create AccountLog in
Avatar of 3can
3can

asked on

Moving data from one SQL database to another

I need to move data from one SQL database to another, I am using SQL Server 2005 but dont know much about it. I can run scripts if someone provides with the code. My knowledge so far has allowed me to setup a new database, run a script to create the tables and set security for the db, and thats Im afraid.

An "SQL for dummies" type explanation would be very much appreciated.




Avatar of Aneesh
Aneesh
Flag of Canada image

Option1 : using "Copy database wizard"
Right click on the database ->Tasks ->Copy database wizard
Now you just need to enter the user credentials and the SQL server instance to which you need to attach this db.
open management studio(SSMS)
--> select the database --> right click --> Export
the export wizard will be opened...
click next
select the source database (from which you want to export your data)
next
select the destination database(to where you want to export)
select the tables you want to export...
complete the wizard...
you data are transfered.
Make a copy of a database using BACKUP and RESTORE
This example uses both the BACKUP and RESTORE statements to make a copy of the Northwind database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY.

Step1.

BACKUP DATABASE Northwind
   TO DISK = 'c:\Northwind.bak'  

Step2.
--now copy that Backupfile and paste at the target machine


Step3.
RESTORE FILELISTONLY
   FROM DISK = 'c:\Northwind.bak'
-- When you run the above statement, it will give ou the logical names, make a note of those names

Step4.
RESTORE DATABASE TestDB
   FROM DISK = 'c:\Northwind.bak'
   WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf',      --- 'Northwind' is the logical name of the MDF file
   MOVE 'Northwind_log' TO 'c:\test\testdb.ldf'            -- 'Northwind_Log' is the logical name of the LDF file

Avatar of 3can
3can

ASKER

Sorry forgot mention I am using:

SQL Server management studio express.

I also only need to copy certian categories from one database.
oops , i thought you want 2 move the entire db , In case you just need to move few tables, you must follow the instructions "JaiGanesh" mentioned.
open management studio(SSMS)
--> select the database --> right click --> Export
the export wizard will be opened...
click next
select the source database (from which you want to export your data)
next
select the destination database(to where you want to export)
select the tables you want to export...
complete the wizard...
you data are transfered.

:-)))
Avatar of 3can

ASKER

JaiGanesh

Dont know if I am being dumb but when I right on the db I only get the following options:
New Database
New Query
Script Database
Tasks
Rename
Delete
Refresh
Properties

When browsing help I found the following command:

bcp Utility

bcp AdventureWorks.Sales.Currency out "Currency Types.dat"

Does this sound like a command I could ?

??


under tasks --> you have EXPORT DATA
(i must have been more clear)
Avatar of 3can

ASKER

From Taksk it goes:

detach
shrink
restore
backup
generate scripts
ASKER CERTIFIED SOLUTION
Avatar of Jai S
Jai S
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer