dd SdeptNo char(2)РgoРdeclare @sno char(10),@total int,@i intРselect @total=count(*),@i=1Рfrom StudentРwhile(@i<=@total)РbeginР?------------查询数据表第@i 行数据的SQL语句Р?select top 1 @sno=Sno from Student where Sno not in(select top (@i-1) Sno from Student) Р?update StudentР?set SDeptNo=substring(@sno,4,2)Р?where Sno=@snoР?set @i=@i+1РendРselect * from StudentРgoР-----------结果如下: Р-------------往学生表S中插入一列"专业号",其值等于学号中代表专业的位的值Рuse LibrarySystemРgoРalter table StudentРadd SMajorNo varchar(50)РgoРdeclare @sno char(10),@total int,@i intРselect @total=count(*),@i=1Рfrom StudentРwhile(@i<=@total)РbeginР?------------查询数据表第@i 行数据的SQL语句Р?select top 1 @sno=Sno from Student where Sno not in(select top (@i-1) Sno from Student) Р?update StudentР?set SMajorNo=substring(@sno,4,4)Р?where Sno=@snoР?set @i=@i+1РendРgo