2

I have table call reviewbook table. Users need to assign 3 different review members to a bookid. They can be any reviewmemberid as long as they are 3 different ones to one bookid. Below is the result that I want. Right now, what i can think of is doing a multiple insert in a query however, the reviewmemberid can be duplicated, which is not what I want. I heard that trigger can be a way of doing this but I have no idea how to apply that. Can someone be kind enough to guide me or maybe if there is a better way of doing this.

   Reviewbook
   -reviewid
   -reviewmemberid
   -bookid

  reviewid  reviewmemberid  bookid
      1           2           1     
      2           3           1
      3           5           1
      4           1           2 
      5           2           2
      6           5           2
      7           1           3
      8           2           3
      9           4           3    



//My current insert code, but this insert code can insert duplicate reviewmemberid.
INSERT ALL INTO REVIEW (REVIEWID,REVIEWMEMBERID,BOOKID)VALUES
(?.?,?) INTO REVIEW
(REVIEWID,REVIEWMEMBERID,BOOKID)VALUES 
(?.?,?) INTO REVIEW
(REVIEWID,REVIEWMEMBERID,BOOKID)VALUES 
(?.?,?) SELECT * FROM DUAL;
Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28
Jason Ching Yuk
  • 894
  • 2
  • 11
  • 30

1 Answers1

0

Another option would be to simply declare a unique index on the columns (REVIEWMEMBERID,BOOKID). The syntax would be

CREATE UNIQUE INDEX book_reviewer_idx
  ON review (reviewmemberid, bookid);

This will ensure that a particular pairing of (reviewmemberid, bookid) appears only once in the table; an attempt to insert a duplicate will raise an error.

Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28