SQL

create trigger cau2_trigger on MONHOC for UPDATE AS if exists (select * from inserted) begin -- Tính điểm trung bình từng sv rồi đưa vào bảng tạm Select PHIEUDANGKY_DIEM.MASV, SUM(PHIEUDANGKY_DIEM.DIEMTK*MONHOC.SOTINCHI)/SUM(MONHOC.SOTINCHI) as 'DIEMTRUNGBINH' INTO #temp_DTB from PHIEUDANGKY_DIEM join SINHVIEN on PHIEUDANGKY_DIEM.MASV = SINHVIEN.MASV join MONHOC on PHIEUDANGKY_DIEM.MAMH = PHIEUDANGKY_DIEM.MAMH Where MONHOC.MAMH = PHIEUDANGKY_DIEM.MAMH GROUP by PHIEUDANGKY_DIEM.MASV -- update Điểm trung bình từng sinh viên trong table SV update SINHVIEN SET SINHVIEN.DIEMTRUNGBINH = #temp_DTB.DIEMTRUNGBINH from SINHVIEN INNER JOIN #temp_DTB on #temp_DTB.MASV = SINHVIEN.MASV Where #temp_DTB.MASV = SINHVIEN.MASV -- Xóa bảng tạm drop table #temp_DTB end

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.