I have created two tables. First table has information of students such as ‘ID, Name and address. The second table has information of books has book_id and book title. The primary key of first table is ID and it is the foreign key in the second table with reference to the first table. I want to set restriction so that when a student issues more than 3 book, the database should not accept it. Until now I have created this trigger:
Create Trigger trig On tblbooks
After Insert
As
If (Select Count(ID) from tblbooks Where ID = 1) > 3
RollBack Transaction
But the problem with this trigger is that I have to specify the ID of the student which I cannot do for every student that issues a book. I want some help to create a trigger that works for all the students without specifying there ID.