如何复制并将相同的表插入不同的数据库(一个Db到另一个Db) [英] How Do I Copy And Insert Same Table To Different Databases(One Db To Another Db)

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

问题描述

如何将同一个表复制并插入到不同的数据库中(一个db到另一个db)

how do i copy and insert same table to different databases(one db to another db)

推荐答案

如果它们都在同一台机器上,那么:



If they are both on the same machine then:

select *
into db2.dbo.table1
from db1.dbo.table1





这将创建table1,如果它还不存在。



它不会设置主键,标识列,外键或约束。插入后你必须改变表格



This will create table1 if it does not already exist.

It will not set up the primary key, identity column, foreign keys or constraints. You will have to alter the table after the insert


你可以通过运行 SQL Server导入和导出向导



您可以导出/导入整个数据库以及只有一些选定的表,看一看。
You can make it by running SQL Server Import and Export Wizard .

You can export / import the whole DB as well as only some selected tables, take a look.


选择*

到TargetDB.dbo.TargetTable
来自SourceDB.dbo.SourceTable的




将在TargetDB中创建一个新表并从SourceTable复制数据。



如果TargetTable已经存在,请使用:



插入TargetDB.dbo.TargetTable(Column1,Column1,...)

选择Column1,Column1,...

来自SourceDB.dbo.SourceTable
select *
into TargetDB.dbo.TargetTable
from SourceDB.dbo.SourceTable

Will create an new Table in TargetDB and copy the data from SourceTable.

If the TargetTable allready exists use:

insert into TargetDB.dbo.TargetTable (Column1,Column1,...)
select Column1,Column1,...
from SourceDB.dbo.SourceTable


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

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