requirement is to transfer all inserted records to one table to another. i ve used a trigger to do it. i m looping through all the inserted records and inserting to new table one record at a time as i have to increment a sequence number in the destination table. but this loop considarably slow when number of inserted rows increase. is there a better way of doing this.
Declare @maxpk int, @count int, @seq int
set @maxpk=(select max(refno) from inserted )
set @count=(select count(1) from inserted)
set @seq=((select max(seq_no) from dbase.dbo.destination))
while @count>0
begin
set @seq=(select @seq+1)
insert into dbase.dbo.destination(orderno,SEQ_NO,PRODUCT_ID,qty)
select ordernumber,@seq,productid ,quantity
from inserted where refno=@maxpk
set @count=(select @count-1)
set @maxpk=(select top 1 refno from inserted where refno<@maxpk)
end
参考书是来源表的主要关键。 是否有办法检查插入的记录的终结,这样就不必开始并维持假装。
and can loop be executed for each record in inserted table so i don t have to find the next record to insert by comparing the value of primary key. using mssql 2005