6. Bố cục luận văn
3.1.4. KNT thống kê danh sách môn học sinh viên được đăng ký mv1b
a) Mục đích:
- Lập danh sách môn học sinh viên được đăng ký. b) Tạo bảng thể hiện KNT:
create table mv1b(
masv character varying(12), mamh int,
tenmh character varying(30) );
c) Khởi tạo dữ liệu:
insert into mv1b
select sinhvien.masv,monhoc.mamh,monhoc.tenmh
from sinhvien join lop on sinhvien.malop=lop.malop join nganh on lop.mang=nganh.mang
join chuongtrinh on nganh.mang=chuongtrinh.mang join monhoc on monhoc.mamh=chuongtrinh.mamh where lop.kyht=chuongtrinh.kythu union distinct select masv,mamh,tenmh from mv3 where diem<5.5 union distinct select masv,monhoc.mamh,monhoc.tenmh
from mv3 join monhoc on mv3.mamh=monhoc.mhtruoc;
d) Tạo các hàm và trigger:
create function sinhvien_mv1b_insert() returns trigger as 'qlsinhvien.dll', 'sinhvien_mv1b_insert' language c strict; create trigger sinhvien_mv1b_insert after insert on sinhvien for each row execute procedure sinhvien_mv1b_insert() ;
create function sinhvien_mv1b_delete() returns trigger as 'qlsinhvien.dll', 'sinhvien_mv1b_delete' language c strict; create trigger sinhvien_mv1b_delete after delete on sinhvien for each row execute procedure sinhvien_mv1b_delete() ;
create function sinhvien_mv1b_update() returns trigger as 'qlsinhvien.dll', 'sinhvien_mv1b_update' language c strict; create trigger sinhvien_mv1b_update after update on sinhvien for each row execute procedure sinhvien_mv1b_update() ;
create function lop_mv1b_update() returns trigger as 'qlsinhvien.dll', 'lop_mv1b_update' language c strict;
create trigger lop_mv1b_update after update on lop for each row execute procedure lop_mv1b_update() ;
create function nganh_mv1b_update() returns trigger as 'qlsinhvien.dll', 'nganh_mv1b_update' language c strict; create trigger nganh_mv1b_update after update on nganh for each row execute procedure nganh_mv1b_update() ;
create function chuongtrinh_mv1b_insertdelete() returns
language c strict;
create trigger chuongtrinh_mv1b_insert after insert on chuongtrinh for each row execute procedure
chuongtrinh_mv1b_insertdelete() ;
create trigger chuongtrinh_mv1b_delete after delete on chuongtrinh for each row execute procedure
chuongtrinh_mv1b_insertdelete() ;
create function chuongtrinh_mv1b_update() returns trigger as 'qlsinhvien.dll', 'chuongtrinh_mv1b_update' language c strict; create trigger chuongtrinh_mv1b_update after update on
chuongtrinh for each row execute procedure chuongtrinh_mv1b_update() ;
create function monhoc_mv1b_update() returns trigger as 'qlsinhvien.dll', 'monhoc_mv1b_update1' language c strict; create trigger monhoc_mv1b_update after update on monhoc for each row execute procedure monhoc_mv1b_update() ;
create function mv3_mv1b_insertdelete() returns trigger as 'qlsinhvien.dll', 'mv3_mv1b_insertdelete' language c strict; create trigger mv3_mv1b_insert after insert on mv3 for each row execute procedure mv3_mv1b_insertdelete() ;
create trigger mv3_mv1b_delete after delete on mv3 for each row execute procedure mv3_mv1b_insertdelete() ;
create function mv3_mv1b_update() returns trigger as 'qlsinhvien.dll', 'mv3_mv1b_update' language c strict;
create trigger mv3_mv1b_update after update on mv3 for each row execute procedure mv3_mv1b_update() ;