Wednesday, March 7, 2012

Copying a table form one database to another

To be brief, I need to copy a table (schema and data) from one SQL Server
(2K) database and to another SQL Server database on the same PC.
With MS Access, I was able to use a SELECT INTO statement to move data
between databases by the use of the IN clause to a newly created table in an
external database, such as . .
SELECT * INTO tablename1 IN 'msaccess database path and name' 'DBTYPE FROM
tablename2
(tablename1 would be a newly created table in the external database,
tablename2 would be the connected database table.)
Can the similar method be employed with SQL Server? (I'm using vb.net 1.1
as my development tool.)
Any help would be greatly appriciated
Thanks
Dave M.Yes, it's possible, but it depends on several things. First, is there should
be a linked server defined on serverb to link to serverA? Must have
permissions to at least read servera data, and write serverb data.
Also, is serverB set to allow a "select into"? It is possible to block this
command.
If everything is set up, you can execute a query like this on the
destination serverb:
Select *
into destbdatabase.dbo.dest_table
from servera.databasename.dbo.source_table
"dave m" wrote:

> To be brief, I need to copy a table (schema and data) from one SQL Server
> (2K) database and to another SQL Server database on the same PC.
> With MS Access, I was able to use a SELECT INTO statement to move data
> between databases by the use of the IN clause to a newly created table in
an
> external database, such as . .
> SELECT * INTO tablename1 IN 'msaccess database path and name' 'DBTYPE FROM
> tablename2
> (tablename1 would be a newly created table in the external database,
> tablename2 would be the connected database table.)
> Can the similar method be employed with SQL Server? (I'm using vb.net 1.
1
> as my development tool.)
> Any help would be greatly appriciated
> Thanks
> Dave M.
>
>|||Depends on what you mean by "schema". If all you want are the fields
and the data contained in them, do the following:
SELECT * INTO db2..table FROM db1..table
If you want the entire table schema, meaning triggers, constraints,
etc, the easiest thing would be to use the DTS import/export tools.
Right-click on the table and choose "Export".|||Try www.sqlscripter.com to script your data.
"dave m" wrote:

> To be brief, I need to copy a table (schema and data) from one SQL Server
> (2K) database and to another SQL Server database on the same PC.
> With MS Access, I was able to use a SELECT INTO statement to move data
> between databases by the use of the IN clause to a newly created table in
an
> external database, such as . .
> SELECT * INTO tablename1 IN 'msaccess database path and name' 'DBTYPE FROM
> tablename2
> (tablename1 would be a newly created table in the external database,
> tablename2 would be the connected database table.)
> Can the similar method be employed with SQL Server? (I'm using vb.net 1.
1
> as my development tool.)
> Any help would be greatly appriciated
> Thanks
> Dave M.
>
>

No comments:

Post a Comment