如何在存储过程中循环插入记录
答案:2 悬赏:60 手机版
解决时间 2021-03-18 07:19
- 提问者网友:爱唱彩虹
- 2021-03-17 09:10
如何在存储过程中循环插入记录
最佳答案
- 五星知识达人网友:笑迎怀羞
- 2021-03-17 09:49
declare @a as int
set @a=1
while(@a<=100)
begin
insert into table1 values('','','','')
set @a=@a+1
if @a>100
break
else
continue
end
set @a=1
while(@a<=100)
begin
insert into table1 values('','','','')
set @a=@a+1
if @a>100
break
else
continue
end
全部回答
- 1楼网友:不如潦草
- 2021-03-17 10:03
用游标:
create procedure up_insertdata
@id int
as
begin
declare @name nvarchar(30)
declare tmpcur cursor for select [id],[name] from a where [id]=isnull(@id,[id])
open tmpcur
fetch next from tmpcur into @id,@name
while @@fetch_status=0
begin
insert into b(title,content,aid) values('','',@id)
fetch next from tmpcur into @id,@name
end
close tmpcur
deallocate tmpcur
end
exec up_insertdata 2
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯