在SQL Server中将表从一个数据库复制到另一个数据库? [英] Copy tables from one database to another in SQL Server?

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

问题描述

如何将表中的列从一个数据库添加到sql server中的另一个数据库



请帮帮我

how to add column in a table from one database to another database in sql server

please help me

推荐答案

第一步是使用Update Table查询添加列。

第二步是将数据从第一个表列复制到另一个。
First step would be add the column using an Update Table query.
Second step would be to copy data from first tables column to another.


假设您的源表和目标表相同,并且两个数据库都在同一个sql server实例中。如果是,则添加具有从源表导入的相同数据类型的列。



Assume that your source table and target table is same and both database are in same sql server instance. If so then you add column with same data-type which you import from source table.

alter table add NewColumnName int null;





然后需要使用更新查询更新该表并加入



then need to update that table with update query with join

update TargetTable set
 MyNewColumnName = T.SourceColumn
FROM SourceDatabase.schema.SourceTable AS T
inner join TargetTable ON TargetTable.PrimaryKey = T.PrimaryKey;





如果源数据库和目标数据库在2个不同的sql server实例/网络中,那么你只需要创建一个链接服务器到您的目标数据库和使用该linkserver引用更新查询。



If your source and target database is in 2 differet sql server instance/network then you just need to create a link server to your target database and use that linkserver reference to the update query.


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

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