how to insert data from one table to another table(database) [duplicate]
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]
精彩评论