Learn how to transfer data to an external file, change the data in the table, and then use the transfer command again to repopulate the table from this external file.
This example transfers data out of, and back into, the same table. However, in a typical user scenario, data would be transferred out of one table and then into a different one.
sp_setup_table_transfer
sp_configure 'max transfer history', 5
Parameter Name Default Memory Used Config Value Run Value Unit Type Instance Name ------------------------- ------- ----------- -------------- -------------------- ------- --------------- --------------- max transfer history 10 0 5 5 bytes dynamic NULL
create table transfer_example ( f1 int, f2 varchar(30), f3 bigdatetime, primary key (f1) ) lock datarows with transfer table on
set nocount on declare @i int, @vc varchar(1024), @bdt bigdatetime select @i = 1 while @i <= 10 begin select @vc = replicate(char(64 + @i), 3 * @i) select @bdt = current_bigdatetime() insert into transfer_example values ( @i, @vc, @bdt ) select @i = @i + 1 end set nocount off
select * from transfer_example order by f1
f1 f2 f3 --------- ------------------------------ ---------------------------- 1 AAA Jul 17 2009 4:40:14.465789PM 2 BBBBBB Jul 17 2009 4:40:14.488003PM 3 CCCCCCCCC Jul 17 2009 4:40:14.511749PM 4 DDDDDDDDDDDD Jul 17 2009 4:40:14.536653PM 5 EEEEEEEEEEEEEEE Jul 17 2009 4:40:14.559480PM 6 FFFFFFFFFFFFFFFFFF Jul 17 2009 4:40:14.583400PM 7 GGGGGGGGGGGGGGGGGGGGG Jul 17 2009 4:40:14.607196PM 8 HHHHHHHHHHHHHHHHHHHHHHHH Jul 17 2009 4:40:14.632152PM 9 IIIIIIIIIIIIIIIIIIIIIIIIIII Jul 17 2009 4:40:14.655184PM 10 JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ Jul 17 2009 4:40:14.678938PM
transfer table transfer_example to 'transfer_example-data.ase' for ase
(10 rows affected)
select id, sequence_id, end_code, ts_floor, ts_ceiling, row_count from spt_TableTransfer where id = object_id('transfer_example')
id sequence_id end_code ts_floor ts_ceiling row_count --------- ----------- -------- ------------- ------------------- 592002109 1 0 0 5309 10
alter table transfer_example set transfer table off
select id, sequence_id, end_code, ts_floor, ts_ceiling, row_count from spt_TableTransfer where id = object_id('transfer_example')
id sequence_id end_code ts_floor ts_ceiling row_count --------- ----------- -------- ------------- ------------------- (0 rows affected
update transfer_example set f2 = 'no data', f3 = 'Jan 1, 1900 12:00:00.000001AM'
(10 rows affected)
select * from transfer_example order by f1
f1 f2 f3 ----------- ------------------------------ --------------------------- 1 no data Jan 1 1900 12:00:00.000001AM 2 no data Jan 1 1900 12:00:00.000001AM 3 no data Jan 1 1900 12:00:00.000001AM 4 no data Jan 1 1900 12:00:00.000001AM 5 no data Jan 1 1900 12:00:00.000001AM 6 no data Jan 1 1900 12:00:00.000001AM 7 no data Jan 1 1900 12:00:00.000001AM 8 no data Jan 1 1900 12:00:00.000001AM 9 no data Jan 1 1900 12:00:00.000001AM 10 no data Jan 1 1900 12:00:00.000001AM (10 rows affected)
transfer table transfer_example from 'transfer_example-data.ase' for ase
(10 rows affected)
select * from transfer_example order by f1
f1 f2 f3 ------- ------------------------------ ---------------------------- 1 AAA Jul 17 2009 4:40:14.465789PM 2 BBBBBB Jul 17 2009 4:40:14.488003PM 3 CCCCCCCCC Jul 17 2009 4:40:14.511749PM 4 DDDDDDDDDDDD Jul 17 2009 4:40:14.536653PM 5 EEEEEEEEEEEEEEE Jul 17 2009 4:40:14.559480PM 6 FFFFFFFFFFFFFFFFFF Jul 17 2009 4:40:14.583400PM 7 GGGGGGGGGGGGGGGGGGGGG Jul 17 2009 4:40:14.607196PM 8 HHHHHHHHHHHHHHHHHHHHHHHH Jul 17 2009 4:40:14.632152PM 9 IIIIIIIIIIIIIIIIIIIIIIIIIII Jul 17 2009 4:40:14.655184PM 10 JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ Jul 17 2009 4:40:14.678938PM
alter table transfer_example set transfer table on
(10 rows affected)