alter trigger studyschema.secon
on studyschema.progress
after insert, update
as
declare @subj2 varchar (20)
declare @subj varchar(30)
declare @ocenka varchar(10)
select @ocenka = ocenka
from inserted
select @subj = p.grup_id + p.subj_ID + p.Teach_ID, @subj2 = s.grup_id + s.Subj_ID + s.Teach_ID
from StudySchema.Progress p inner join StudySchema.study s on p.Subj_ID=s.Subj_ID inner join inserted i on p.OCENKA=i.OCENKA
if @subj <> @subj2
begin
rollback tran raiserror ('Количество оценок не может привешать количество предметов',16,10)
end;