User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 402,915 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,103 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 650 | Replies: 4
Reply
Join Date: Dec 2007
Posts: 2
Reputation: mayzebra is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mayzebra mayzebra is offline Offline
Newbie Poster

Importing SQL Tables from one database to another

  #1  
Jul 16th, 2008
I'm trying to find information on how to import selected data from one SQL database to another using C# (or any language for that matter) or the cmd line. aka: I dont want to use the wizard.

I could export to a CSV file, then import... but that seems needslessly complicated and (run) time consuming. Any suggestions?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Posts: 20
Reputation: AmirBedair is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
AmirBedair AmirBedair is offline Offline
Newbie Poster

Re: Importing SQL Tables from one database to another

  #2  
Jul 27th, 2008
Dear mayzebra ,

if you need to make copy (x) tables in database 1 to database 2 with same data.

you can better make a database replication.
check this link
http://technet.microsoft.com/en-us/l...chNet.10).aspx


but if you want to do this by code to make changes in data or specific data to be moved..

first solution : If the 2 database in same server

you can make stored procedure in SQL:
with command
like this:

insert into database1.dbo.table1 (col1,col2,col3)
select col4,col5,col6 from database2.dbo.table2
where (where condation) 

If I don't understand your questions, explain more, and I will help you as I can
Amir S.Bedair
Senior Solution Developer
Please rate my answer
Reply With Quote  
Join Date: Mar 2007
Posts: 50
Reputation: FaridMasood is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
FaridMasood's Avatar
FaridMasood FaridMasood is offline Offline
Junior Poster in Training

Re: Importing SQL Tables from one database to another

  #3  
Jul 29th, 2008
Here is the command prompt commands to generate hte script of database tables and the data in these tables.

But to use these commands you have to download and install "DatabasePublishingWizard" this will create the "sqlpubwiz.exe" at your installation directory. This tool is not installed if you are using the sqlexpress 2005

Command to run which will create schema and database:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks “C:\AdventureWorks.sql”

Command to run which will create schema:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks “C:\AdventureWorks.sql” -schemaonly

Command to run which will create data:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks “C:\AdventureWorks.sql” -dataonly
Thanks and Best of Lusk,

Farid ud din Masood
MS.c (CS)
University of Agriculture, Faisalabad
Reply With Quote  
Join Date: Aug 2008
Posts: 1
Reputation: tharakaw is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tharakaw tharakaw is offline Offline
Newbie Poster

Re: Importing SQL Tables from one database to another

  #4  
15 Days Ago
Originally Posted by AmirBedair View Post
Dear mayzebra ,

if you need to make copy (x) tables in database 1 to database 2 with same data.

you can better make a database replication.
check this link
http://technet.microsoft.com/en-us/l...chNet.10).aspx


but if you want to do this by code to make changes in data or specific data to be moved..

first solution : If the 2 database in same server

you can make stored procedure in SQL:
with command
like this:

insert into database1.dbo.table1 (col1,col2,col3)
select col4,col5,col6 from database2.dbo.table2
where (where condation) 

If I don't understand your questions, explain more, and I will help you as I can
hi Amir,

how to do the same, if the databases are in two different servers
Reply With Quote  
Join Date: Jul 2008
Posts: 20
Reputation: AmirBedair is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
AmirBedair AmirBedair is offline Offline
Newbie Poster

Re: Importing SQL Tables from one database to another

  #5  
15 Days Ago
Dear tharakaw

Please read MSDN help and check all the child pages from how to configure and make linked server :
http://msdn.microsoft.com/en-us/library/ms188279.aspx

regards,
Amir
Amir S.Bedair
Senior Solution Developer
Please rate my answer
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C# Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 3:58 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC