顶牛部落,柜台西施漫画,警长汉化
简单使用游标插入数据
--创建数据库 create proc insertstudent as --定义所需要的变量 declare @schoolid int declare @classid int declare @studentid int declare @idnumber int --条件判断时需要 begin --创建游标 declare feeinsertstudent cursor for select stuid,schid,clasid from t_school --打开游标 open feeinsertstudent --从游标里取出数据给 变量 赋值 fetch next from feeinsertstudent into @schoolid,@classid,@studentid --判断有标的状态 while @@fetch_status=0 begin --为变量赋值 set @idnumber=(select count(*) from t_leaveschool where studentid=@studentid and schoolid=@schoolid and classid=@classid) if(@idnumber=0) --判断 begin insert into t_leaveschool(studentid,classid,schoolid) values( @studentid,@classid,@studentid) end fetch next from feeinsertstudent into @schoolid,@classid,@studentid end close feeinsertstudent --关闭游标 deallocate feeinsertstudent --撤销游标 end
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
数据库SQL---数据库、基本表、视图、索引的定义、修改、删除
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (上)
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (下)
网友评论