CREATE TRIGGER GetCount on teachers after insert as begin declare @totalCount int--表变量里面总共的变量条数 declare @RowNo int--当前是多少行 declare @tempId int--保存当前行的id declare @classCount int--保存当前班级的数量 declare @temp1 table(indexid int identity(1,1) not null,id int) insert into @temp1 select ID from Students set @totalCount=@@ROWCOUNT set @RowNo=1 while @RowNo <= @totalCount begin select @tempId=id from @temp1 where indexid = @RowNo select @classCount=COUNT(*) from Students where ClassName=@tempId update teachers set [email protected] where ID=@tempId set @RowNo = @RowNo+1 end end
时间: 2024-10-12 15:10:20