The document contains SQL code to modify a database by adding a new column 'DG' to the 'subject' table. It defines two stored procedures: 'FillDGSub', which updates the 'DG' column based on student results, and 'FillSub', which iterates through subjects with 4 credits to execute 'FillDGSub'. The procedures ensure that the 'DG' value reflects whether students have passed or failed based on their marks.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views2 pages
Alter Table Subject
The document contains SQL code to modify a database by adding a new column 'DG' to the 'subject' table. It defines two stored procedures: 'FillDGSub', which updates the 'DG' column based on student results, and 'FillSub', which iterates through subjects with 4 credits to execute 'FillDGSub'. The procedures ensure that the 'DG' value reflects whether students have passed or failed based on their marks.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
alter table subject
add DG nvarchar(20)
create proc FillDGSub
@subjectID varchar(50) as begin if (not exists (select * from Subject where ID=@subjectID)) return declare @sltd int select @sltd=COUNT(*) from result r where r.subjectID=@subjectID and r.Mark>=5 and r.times > = all (select r1.times from result r1 where r1.studentID=r.StudentID and r1.subjectID=r.SubjectID) if(@sltd>=1) begin declare @min float select @min=MIN(r.mark) from result r where r.subjectID=@subjectID declare @dg nvarchar(20) if(@min>5) set @dg = N'đạt' else begin set @dg= N'không đạt' end update subject set DG=@dg where ID=@subjectID end end go create proc FillSub as begin declare c cursor for (select ID from subject where credit=4) open c declare @ID varchar(50) fetch next from c into @ID while(@@fetch_status=0) begin exec FillDGSub @ID fetch next from c into @ID end close c deallocate c end