1

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 violated by changes to the teaches relation as well as to the section relation).

I am self-learning SQL using Database System Concept and get pretty confused aboutsee the pic how trigger is enforced. Any inputs are appreciated!

macintosh81
  • 189
  • 1
  • 12
  • The trigger can raise an error and effectively abort the transaction. The syntax is different for each DB. What DB are you learning? – cha Oct 29 '15 at 03:34
  • Thanks, cha. The textbook I am reading does not deal with a certain DB. It only broadly talks about SQL in general. Below is an example from the textbook. I am not sure if the code is executable or not. create trigger timeslot check1 after insert on section referencing new row as nrow for each row when (nrow.time slot id not in ( select time slot id from time slot)) /* time slot id not present in time slot */ begin rollback end; – macintosh81 Oct 29 '15 at 05:14
  • I guess in this case you can just `ROLLBACK TRANSACTION` – cha Oct 29 '15 at 05:17
  • Thanks! I just upload the book code http://i.stack.imgur.com/9WHMt.png. Do you think I should write the same way? – macintosh81 Oct 29 '15 at 05:19
  • Yes, rollback is a pretty standard way to control the data integrity – cha Oct 29 '15 at 05:21
  • Thank you! Could you write a short code to implement this question? I am kind of confused to make out the meaning of the sentence – macintosh81 Oct 29 '15 at 05:28

0 Answers0