Show how to enforce the constraint "an instructor cannot teach in two different classrooms in a semester in the same time slot." using a trigger (remember that the constraint can be viloated by changes to the teaches relation as well as to thesection relation).
请编写一个触发器!谢啦
teaches表
section表
------解决方案--------------------
create trigger time_check on teaches
after insert, update
as
if exist(new.time_lot=time_lot)
begin
RAISERROR('error msg', 16, 1);
rollback transaction;
return
end;
------解决方案--------------------
if exist (select count(distinct time_slot_id) as dtc, count(time_slot_id) as tc
from teaches as t natural join secion as s natural join instructor as i
group by id
having dtc != tc)then......
这次应该行了!测试通过!