开发者

how to insert data from one table to another table(database) [duplicate]

开发者 https://www.devze.com 2023-02-08 19:04 出处:网络
This question already has answers here: How to update data in one table from corresponding data in another table in SQL Server 2005
This question already has answers here: How to update data in one table from corresponding data in another table in SQL Server 2005 (8开发者_开发百科 answers) Closed 9 years ago.

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]

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

original answer:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号