1.insert into TabA
select col1,col2,col3
from TabB
where...2.declare mycursor cursor for
select col1,col2,col3
from TabB
where..
open cursor
fetch mycursor into val1,val2,val3
while @@sqlstatus=0 do
begin
insert into TabA values(val1,val2,val3)
fetch mycursor into val1,val2,val3
end我不知道这两种写法有什么区别,那个用的更多一点在事务中。
1方法如果有一条插入失败,@@error的值是否不为0,而且先前插入的
记录行全部回滚掉。
2方法如果某一条记录插入失败的话,其他已经插入的记录是否也自动回滚,
而且在循环结束后@@error的值是否也不为0?
这个问题困扰我很久了,希望高手能够指点!!
select col1,col2,col3
from TabB
where...2.declare mycursor cursor for
select col1,col2,col3
from TabB
where..
open cursor
fetch mycursor into val1,val2,val3
while @@sqlstatus=0 do
begin
insert into TabA values(val1,val2,val3)
fetch mycursor into val1,val2,val3
end我不知道这两种写法有什么区别,那个用的更多一点在事务中。
1方法如果有一条插入失败,@@error的值是否不为0,而且先前插入的
记录行全部回滚掉。
2方法如果某一条记录插入失败的话,其他已经插入的记录是否也自动回滚,
而且在循环结束后@@error的值是否也不为0?
这个问题困扰我很久了,希望高手能够指点!!
后一种方法,一般适于要对取出的记录进行处理,然后再执行插入,否则的话,就效率而言就是不合算的。
所以第二种方法才不会回滚已插入数据