可以用游标来删除表中所有数据么?想插入一行删除一行,可以么 是从A表往B里插入数据,然后把B里的这条数据删除------------------------当然可以:declare 游标 cursor for select ??? from A open 游标 fetch next from 游标 into ??? while @@fetch_status=0 begin insert into B values(???) delete from A where current of 游标 --删除当前行 fetch next from 游标 into ??? end close 游标 deallocate 游标
declare 游标 cursor for select ??? from A open 游标 fetch next from 游标 into ??? while @@fetch_status=0 begin insert into B values(???) delete from A where current of 游标 --删除当前行 fetch next from 游标 into ??? end close 游标 deallocate 游标 ============================================== 这样试了一下说是readonly的,那为什么还可以插入呢
我加上了scroll_locks或者optimistic都不行
SCROLL_LOCKS指定确保通过游标完成的定位更新或定位删除可以成功。当将行读入游标以确保它们可用于以后的修改时,Microsoft SQL Server 会锁定这些行。如果还指定了 FAST_FORWARD,则不能指定 SCROLL_LOCKS。OPTIMISTIC指定如果行自从被读入游标以来已得到更新,则通过游标进行的定位更新或定位删除不成功。当将行读入游标时 SQL Server 不锁定行。相反,SQL Server 使用 timestamp 列值的比较,或者如果表没有 timestamp 列则使用校验值,以确定将行读入游标后是否已修改该行。如果已修改该行,尝试进行的定位更新或定位删除将失败。如果还指定了 FAST_FORWARD,则不能指定 OPTIMISTIC。
没有指定FAST_FORWARD关键字,为什么还是不行呢
是不是声明了只读游标,不要定要 READ_ONLY 关键字,象 ORDER BY 之类的都有可能导致游标只读。
---
不是白玩了么。。
是从A表往B里插入数据,然后把B里的这条数据删除------------------------当然可以:declare 游标 cursor for select ??? from A
open 游标
fetch next from 游标 into ???
while @@fetch_status=0
begin
insert into B values(???)
delete from A where current of 游标 --删除当前行
fetch next from 游标 into ???
end
close 游标
deallocate 游标
open 游标
fetch next from 游标 into ???
while @@fetch_status=0
begin
insert into B values(???)
delete from A where current of 游标 --删除当前行
fetch next from 游标 into ???
end
close 游标
deallocate 游标
==============================================
这样试了一下说是readonly的,那为什么还可以插入呢
题目是这个意思吧