标签:style blog color ar 数据 sp div c on
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 classCount=@classCount where ID=@tempId set @RowNo = @RowNo+1 end end
标签:style blog color ar 数据 sp div c on
原文地址:http://www.cnblogs.com/zwhFighting/p/4007814.html