Thursday, April 18, 2013

Transfer Data of Table from One Database to Another in SQL Server



DECLARE c1 CURSOR READ_ONLY
FOR select id,name from  database1.dbo.t1

declare @id int --(Change Datatype respectively)
declare @name varchar(50)

open c1
FETCH NEXT FROM c1
Into @id, @name

WHILE @@FETCH_STATUS = 0
BEGIN

Insert into [test].[dbo].t1
(
    id,
    name
  
)
values
(@id, @name)

FETCH NEXT FROM c1
Into @id, @name
END CLOSE c1
DEALLOCATE c1

No comments:

Post a Comment