- alter table sc
- add GPA float; --加入绩点列
- alter table sc
- add number int identity(1,1);--将表按原始位置顺序编号(可加可不加)
- alter table sc add primary key(number)
- declare score_visit cursor --声明一个游标
- for select score from sc
- open score_visit --打开游标
- declare @GPA float
- select @GPA=score from sc
- fetch next from score_visit into @GPA
- while @@fetch_status=0 --循环读取
- begin
- if @GPA>=90
- update sc set GPA=4.0 where current of score_visit;
- if @GPA >=85 and @GPA <90
- update sc set GPA =3.7 where current of score_visit;
- if @GPA >=82 and @GPA <85
- update sc set GPA =3.3 where current of score_visit;
- if @GPA >=78 and @GPA <81
- update sc set GPA =3.0 where current of score_visit;
- if @GPA >=75 and @GPA <78
- update sc set GPA =2.7 where current of score_visit;
- if @GPA >=72 and @GPA <75
- update sc set GPA =2.3 where current of score_visit;
- if @GPA >=68 and @GPA <72
- update sc set GPA =2.0 where current of score_visit;
- if @GPA >=64 and @GPA <68
- update sc set GPA =1.5 where current of score_visit;
- if @GPA >=60 and @GPA <64
- update sc set GPA =1.0 where current of score_visit;
- if @GPA <60
- update sc set GPA =0 where current of score_visit;
- fetch next from score_visit into @GPA
- end
- close score_visit --关闭游标
- deallocate score_visit --删除游标