Re: Script to copy table between databases

From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 02/19/04


Date: Thu, 19 Feb 2004 19:26:19 +0530

hi newbie,

There isn't any built in tool available with sql server that will script the
data like "insert into....". If you want to do a data transfer between the
database you have various optios with you.

1) backup/restore of database
--above option will be useful to create a complete replica of the database
on to the destination database.
2) DTS.
--can be used to transfer selective objects from the database.
3) bcp/bulk insert.

With the help of bcp command you can transfer the data to and from the ascii
files. whereas with the help of "bulk insert" command you can only insert
data from ascii/flat files into the database. To create a complete
definition of the table structures you can take help of "Enterprise manager"
scripting option. Open the enterprise manager, right click on the database.
click on "all tasks" . click on "generate sql script". click on "show all".
Select the objects you wish to script (all tables/all sps etc.). this will
generate a script file with DDL commands. Run this file on the second
database where you want to generate similar database structure, and later
you can transfer the data from the ascii files that has been generated with
the help of BCP command.

4) But above all i think you can make use of "INSERT INTO...SELECT "
statement becase as you stated "destination table already exists and is
identical in design".
So your syntax will look something like this.

insert into db_name.owner.<destination_table> (col1,col2) select col1,col2
from db_name.owner.<source_table>

I understand from your statement "I need to overwrite the destination table
data if it already exists" that, you want to empty the destination table
which, can be accomplished using:

"TRUNCATE TABLE <table>" or "DELETE FROM <table>" command. if you want to
completely empty the table use TRUNCATE TABLE command which is faster.

--
Vishal Parkar
vgparkar@yahoo.co.in


Relevant Pages

  • RE: problem with DBD::Oracle
    ... Next, if it runs from the command line, then you most likely have a permissions issue with either the Perl script itself, or the Oracle.so library. ... Oracle database that is on a different machine. ... sender of the delivery error by replying to this message, or notify us by ...
    (perl.dbi.users)
  • Re: mysql connection failing as CGI
    ... some new hosting which comes with a MySQL database but I'm struggling ... to get it working with any perl scripts; the hosting support are being ... The problem basically is that when the script is run as a CGI script it ... the command line it runs fine. ...
    (comp.lang.perl.misc)
  • mysql connection failing as CGI
    ... some new hosting which comes with a MySQL database but I'm struggling ... to get it working with any perl scripts; the hosting support are being ... The problem basically is that when the script is run as a CGI script it ... the command line it runs fine. ...
    (comp.lang.perl.misc)
  • Re: How do I Edit a list of files associated with a product ?
    ... So it succesfully adds the product and the files in a database and the filesystem. ... and you have done something like that or you know a url or script that does that, ... Just build an edit command with the selected file name and ... you better check out the syntax for the exec command since it has additional parameters. ...
    (comp.lang.php)
  • Re: Oracle database not starting up after reboot on RedHat ES4 Linux !
    ... I have Oracle database enterprise edition 9.2.0.4 running on RedHat ... I am using dbstart command via a /etc/init.d/oracle file. ... When working with shell scripts that are executed by cron or on system startup, it is often useful to run those scripts in a manner that does not have your environment included in the execution of that script. ...
    (comp.databases.oracle.server)