如何将数据从一个表插入到另一个表(数据库) [英] how to insert data from one table to another table(database)

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

问题描述

我在同一台服务器上有两个数据库(test1test2),它们具有相同方案的相同表(Employee).Employee 包含大约 1.500 行.现在我想为每个 PK 复制列 EmpDepID 的值.

I have two databases (test1 and test2) on the same server, which have the same tables (Employee) with the same scheme. Employee holds around 1.500 rows. Now I want to copy the value of column EmpDepID for each PK.

我怎样才能做到这一点?

How can I achieve this?

推荐答案

UPDATE [test1].[dbo].[Employee]
SET [EmpDepID] = test2.[EmpDepID]
FROM [test2].[dbo].[Employee] test2
WHERE test2.[PK] = [test1].[dbo].[Employee].[PK]

正如@AdiInbar 所说,这个问题的明显意图是完全不同的.

as stated by @AdiInbar, the obvious intention of this question was something completely different.

原答案:

INSERT INTO [database1].[dbo].[table1]
(
    /* TODO: define columns */
)
SELECT  * /* or specify the columns */
FROM    [database2].[dbo].[table2]

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

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