如何将数据库的一个表复制到另一个数据库. [英] How to copy one table of Database to another database.

查看:154
本文介绍了如何将数据库的一个表复制到另一个数据库.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我正在使用Sqlserver2005.

我有一个名称为SchoolDb的数据库....在此表中有一个名为StudentInformation的表,该表中有大量记录.

我还有一个名称为CollegeDb的数据库,在该数据库中,我需要复制学生信息表.


请您能帮我怎么做.

感谢EVER.

Dear Friends,

Am working on Sqlserver 2005.

I have a DATABASE with Name SchoolDb.... in this i have a table called StudentInformation with Large number of Records in this table.

I have another DATABASE with Name CollegeDb, In this Database I need to copy Student information table.


Please can you help me how to do this.

Thanks for EVER.

推荐答案

您好,软英语....


请使用以下查询.

它将对您有帮助.


Hello Soft Engg....


Please use the below query.

It will help you.


select * into CollegeDb..newstudentinfo(DBname..tableName) from SchoolDb..StudentInformation (DBname..tableName)


尝试在ADO.Net中使用SqlBulkCopy方法. br/> 代码:
try to use SqlBulkCopy Method in ADO.Net.
Code:
DataTable sourceDataTable = new DataTable(); //here select data from your source database
string DestinationConnString = ""; //here place your destination databse connection string
string DestinationTableName = ""; //here your destination Table name
SqlBulkCopy bulkDataCopy = new SqlBulkCopy(DestinationConnString, SqlBulkCopyOptions.TableLock)
{
          DestinationTableName = DestinationTableName,
          BatchSize = 100000,
          BulkCopyTimeout = 360
};
bulkDataCopy.WriteToServer(sourceDataTable);



使用此查询:

Hi,
Use this query:

select * into tstTbl from TestDB.dbo.Table1



这会将表1的所有数据(表1在TestDB数据库内部)复制到当前表"tstTb".


--Amit



This will copy all the data of Table1(Table1 is inside TestDB database) to the current table "tstTb" .


--Amit


这篇关于如何将数据库的一个表复制到另一个数据库.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆